I am trying to have free scales on a Boxplot image with faceting.
Using this example dataset, if I try this:
ggplot(data=mpg) +
geom_boxplot(aes(x=cty, y=model))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")
Plot incorrect boxplot http://dl.dropbox.com/u/9788680/plot1.png
Here, the free scales are implemented exactly as I would like, with the different scales for the y-axis depending on the number of available factors for a horizontal facet rule. The boxplots are however not correctly depicted (i.e. as solid lines instead of boxplots). When searching for a solution, I found that I should use coord_flip() in order to make the boxplot be depicted correctly, i.e.
ggplot(data=mpg) +
geom_boxplot(aes(x=model,y=cty))+
facet_grid(manufacturer ~ drv, scales = "free", space = "free")+
coord_flip()
Plot correct boxplot, but no scaling http://dl.dropbox.com/u/9788680/plot2.png
In above picture, the boxplots are now correct. However, the free scale for the factors (so on the y-axis) are removed. Now, for each horizontal facet line, ALL the available factors across the dataset are now included, instead of only the factors available for each facet (as in Figure 1).
I would like to know how I can get the correct facetting with a free scale on both axes, correctly depicting the boxplot.
If somebody could point me in the right direction, I would be grateful.
Thanks.
coord_flip()
callscoord_cartesian
notscale_continuous
.scale_
andcoord_
affect the plot differently. It might be worth reporting this as anissue
at https://github.com/hadley/ggplot2 – mnelcoord_flip()
, but that messes up the faceting scales, like you see. See groups.google.com/d/msg/ggplot2/u5a1mpnJR7E/XxwXWNDX77MJ – Brian Diggs