-2

I followed this tutorial to use barplot. However, I am having hard time to put numbers on top of bars. I spent all day without much luck. Can anyone help, please?

I've attached .zip with data, plotting script and the graphs I have now. Basically, the numbers on the middle of the bars (on black) should be on top of each bar and with respective value. Right now, I just got max across all bars (which is wrong). Extract ZIP and type "Rscript plot-storage.R ." inside the extracted folder to execute the script.

Thanks,

Nodir

Nodir Kodirov
  • 899
  • 1
  • 10
  • 16
  • 2
    It's so silly to put numbers on top of bar plots. What the point of the plot any more, why not just make a table of numbers? It's best to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) directly in the question itself. It's not polite to ask others to download a potentially dangerous ZIP file. You should probably simplify the data and code to make the problem as clear as possible. – MrFlick Dec 08 '15 at 01:54
  • 1
    Possible duplicate: http://stackoverflow.com/questions/12481430/how-to-display-the-frequency-at-the-top-of-each-factor-in-a-barplot-in-r/12483754#12483754 – MrFlick Dec 08 '15 at 01:55
  • Thanks for the pointer on duplicate @MrFlick and apologies for not providing reproducible example. I solved the problem by looking at the duplicate question you provided. I am going to put a solution excerpt as an example. – Nodir Kodirov Dec 08 '15 at 05:33

1 Answers1

0

I solved the problem by looking at the URL marked as a duplicate. Thanks to MrFlick!

I had following to plot the bars:

[...]
data <- structure(list(vdb, vdc, vdd, vde), 
                  .Names = c("4K", "16K", "32K", "64K"), 
                  class = "data.frame", row.names = c(NA, 4L))
colours <- c("green", "orange", "blue", "red")
barObj <- barplot(as.matrix(data), main=title, ylab = "IOPS (log scale)", 
                  cex.lab = 1.2, cex.main = 1.4, 
                  beside=TRUE, col=colours, log="y")
legend("topright", c("B", "C", "D", "E"), cex=1.3, bty="n", fill=colours)

Adding following two lines put numbers on top of bars.

[...]
data <- structure(list(vdb, vdc, vdd, vde), 
                  .Names = c("4K", "16K", "32K", "64K"), 
                  class = "data.frame", row.names = c(NA, 4L))
values = c(vdb, vdc, vdd, vde) # added line
colours <- c("green", "orange", "blue", "red")
barObj <- barplot(as.matrix(data), main=title, ylab = "IOPS (log scale)", 
                  cex.lab = 1.2, cex.main = 1.4, 
                  beside=TRUE, col=colours, log="y")
text(x=barObj, y=values, label=values, cex=0.9, pos=3, col="black", xpd=TRUE) # added line
legend("topright", c("B", "C", "D", "E"), cex=1.3, bty="n", fill=colours)
Nodir Kodirov
  • 899
  • 1
  • 10
  • 16