reversing labels after coord_flip()

2,940 views
Skip to first unread message

Alan Kelly

unread,
Dec 8, 2010, 1:21:44 PM12/8/10
to ggplot2
Hi all,  I'm using a forest plot to present the coordinates (plus and minus upper and lower confidence intervals) of a model based on the function supplied by Abhijit (http://www.r-bloggers.com/forest-plots-using-r-and-ggplot2/) after some necessary editing.  This function uses coord_flip() to reverse axes and, as a consequence, the y-axis is presented in reverse order.
A simple example of this effect is part of help for coord_flip as follows:

qplot(cut, price, data=diamonds, geom="boxplot")
# following this plot the order is "fair" to "ideal" as seems sensible. Now use coord_flip():

last_plot() + coord_flip()
# after the coord_flip() the order is "ideal" to "fair".

While using coord_flip() is it possible to ensure that the order is as intended e.g. "fair" to "ideal"?

Thanks for any suggestions,
Alan Kelly


Brandon Hurr

unread,
Dec 8, 2010, 3:13:31 PM12/8/10
to Alan Kelly, ggplot2
diamonds$cut<-factor(diamonds$cut, levels=rev(levels(diamonds$cut)))

qplot(cut, price, data=diamonds, geom="boxplot")

last_plot() + coord_flip()

Should work...





On Wed, Dec 8, 2010 at 18:21, Alan Kelly <AKE...@tcd.ie> wrote:
last_plot() + coord_flip()

revflip.png

Alan Kelly

unread,
Dec 9, 2010, 6:44:05 AM12/9/10
to Brandon Hurr, ggplot2
Brandon - many thanks, this worked nicely.
Alan


<revflip.png>

Reply all
Reply to author
Forward
0 new messages