1

When I do this:

barplot(c(1,2,3),ylim=c(4,1))

I expect the first bar in the barplot to go from 4 to 1. The second bar should go from 4 to 2 and so on. But that's not what I get. How can I achieve this?

Thomas
  • 43,637
  • 12
  • 109
  • 140
user3182532
  • 1,097
  • 5
  • 22
  • 37
  • The first argument to `barplots` is the heights of the bars, not the stopping points (they'll still start at 0, regardless of your axis limits, as far as I know). If you want to draw boxes at arbitrary coordinates as opposed to starting at the x-axis, look into `polygon` or `rect`. – MDe Feb 20 '14 at 15:27

2 Answers2

4

It sounds like you probably want barplot(c(1,2,3),ylim=c(4,0)), which yields:

enter image description here

But it also sounds like you might be asking for (the somewhat confusing) barplot below:

barplot(c(3,2,1),ylim=c(0,4), yaxt='n')
axis(2, 0:4, 4:0)

enter image description here

Thomas
  • 43,637
  • 12
  • 109
  • 140
0

In the spirit of Thomas' code, you also might want this:

barplot(4 - c(1,2,3),ylim=c(4,0), yaxt='n')
axis(2, 0:4, 4:0)

enter image description here

Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112