Wayward Boxplot!

So I was trying to make this boxplot in the 'R for data science' book:

ggplot(data = smaller, mapping = aes(x = carat, y = price)) +
geom_boxplot(mapping = aes(group = cut_width(carat, 0.1)))

according to the book it should look like this:

but when I run the code a different result comes about.(picture in the next comment)

anyway to go around it?

this is what I actually get by running the code:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Thanks for the super quick reply.

This is happening because of a new feature in ggplot2, now horizontal plots are supported natively but some times it guesses the orientation wrong. You can fix it by explicitly setting the orientation.

geom_boxplot(mapping = aes(group = cut_width(carat, 0.1)), orientation = "x")
2 Likes