Jim G. Jim G. - 1 year ago 118
R Question

How can I flip and then zoom in on a boxplot?

Consider the following code:

ggplot(diamonds, aes("", price)) + geom_boxplot() + coord_flip()

Diamond Prices

After flipping the box plot, how can I zoom in to
on price (which is the new x-axis)?

I feel like it has something to do with
coord_cartesian(ylim=c(0, 7000))
, but this doesn't seem to work in conjunction with

Answer Source

Here is my solution:

ggplot(diamonds, aes("", price)) + 
  geom_boxplot() + 
  coord_flip(ylim=c(0, 7000))

Just combine the ylim command as argument in coord_flip().

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download