5ce838669ec36aedcf37a394a3067a2190af2a50
max
  Tue Nov 3 06:28:49 2020 -0800
reverse bigBarChart order of bars on hgc page, refs #26461

diff --git src/hg/hgc/hgcData/barChartBoxplot.R src/hg/hgc/hgcData/barChartBoxplot.R
index 1a729db..780e905 100644
--- src/hg/hgc/hgcData/barChartBoxplot.R
+++ src/hg/hgc/hgcData/barChartBoxplot.R
@@ -44,56 +44,59 @@
         text(1:count, y1 + adjust, exprPlot$n, cex=size, col="black")
         # add sample (X axis) labels at 45 degree angle
         rot <- 45
         size <- 1
         text(1:count, y1 - adjust, cex=size, labels=labels, srt=rot, xpd=TRUE, adj=c(1,.5), col="black")
         text(1:count, y1 - adjust, cex=size, labels=labels, srt=rot, xpd=TRUE, adj=c(1,.5), col=colorsHex)
     }
     else { 
         # new-style vertical bars, easier to read
         size <- .7
         longestLabelIdx = which.max(nchar(labels))
         longestLabel = labels[longestLabelIdx]
         marLeft = nchar(longestLabel)/2.5 # 2.5 was trial and error, strwidth(longestLabel, "inches") didn't work
         par(mar=c(3,marLeft,2,1) + 0.1, mgp=c(2,1,0), font.main=1)
         yLimit <- c(-(max*.02), max+ (max*.03))
+        # by default, the order of horizontal barcharts is reversed compared to vertical barcharts
+        # this is why we inverse the order with at=rev(...) and later for text() apply rev(...) on all y-coords
         exprPlot <- boxplot(value ~ df$category, data=df, xlab=yLabel, ylim=yLimit, xlim=c(0, count),
+                        at=rev(1:nlevels(df$category)),
                         main=title, 
                         horizontal=TRUE,
                         space = 0.3,
                         col=colorsHex, border=c(darkgray),
                         # medians
                         medcol="black", medlwd=2,
                         # outliers
                         outcex=.5, outcol=darkgray,
                         # whiskers
                         whisklty=1, whiskcol=gray, 
                         # 'staples'
                         staplecol=gray, staplecex=1.3, staplewex=.8,
                         # erase y ticks
                         yaxt="n",
                         # erase X axis labels (add later rotated)
                         names=rep(c(""), count))
         y1 <- par("usr")[1]
         # draw numbers only black, at 90 degrees and left-adjusted
         rot <- 0
         adjust <- .15*abs(y1)
-        text(y1 + adjust, 1:count, exprPlot$n, cex=size, col="black", srt=rot, adj=0.0)
+        text(y1 + adjust, rev(1:count), exprPlot$n, cex=size, col="black", srt=rot, adj=0.0)
         # draw labels
         size <- .9
         adjust <- .4*abs(y1)
-        text(y1-adjust, 1:count, cex=size, labels=labels, srt=rot, xpd=TRUE, adj=c(1,.5), col="black")
+        text(y1-adjust, rev(1:count), cex=size, labels=labels, srt=rot, xpd=TRUE, adj=c(1,.5), col="black")
     }
 }
 
 drawBarPlot <- function(df) {
     yLimit <- c(-(max*.02), max+ (max*.03))
     par(mar=c(marBottom,marLeft,3,1) + 0.1, mgp=c(2.5,1,0), font.main=1)
     df <- df[(order(match(df$category, colorDf$category))),]
     exprPlot <- barplot(df$value, ylab=yLabel, ylim=yLimit,
                         main=title,
                         col=colorsHex, border=c(darkgray),
                         # erase X axis labels (add later rotated)
                         names.arg=rep(c(""), count))
     limits <- par("usr")
     xmin <- limits[1]
     xmax <- limits[2]