user3182532
user3182532

Reputation: 1127

Invert y-axis in barplot

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?

Upvotes: 1

Views: 5458

Answers (2)

Matthew Lundberg
Matthew Lundberg

Reputation: 42629

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

Upvotes: 0

Thomas
Thomas

Reputation: 44527

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

Upvotes: 4

Related Questions