ggplot geom_bar - 'rotate and flip'?

Viewed 14673
test <- data.frame(
    y=seq(18,41,1),
    x=24:1
)

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts( axis.text.x = theme_blank(), axis.ticks.x = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + 
    coord_cartesian(ylim = c(17, 42))

enter image description here

As far as the rotating and flipping is concerned, I'd like what is the y axis in this plot to be along the top, and what is the x axis to be down the right hand side. So the bars are coming 'out' of the right hand side of the plot, with the longest/tallest at the top, shortest at the bottom. If it's rotated clockwise 90 degrees, and then flipped over a vertical line that would achieve it.

coord_flip() and scale_y_reverse() get someway down the right path.

Edit:

I guess this is pretty close, just need to get that y axis to the top of the graph.

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts(axis.text.y = theme_blank(), axis.ticks.y = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + scale_y_reverse() + coord_flip()  + scale_x_reverse()
1 Answers
Related