ggplot2, facet_grid, free scales?

RGgplot2

R Problem Overview


In the following example, how do I get the y-axis limits to scale according to the data in each panel?

mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() 

Neither of these will do it:

mt + facet_grid(. ~ cyl, scales="free")
mt + facet_grid(. ~ cyl, scales="free_y")

R Solutions


Solution 1 - R

Perhaps it's because you have only one y axis, using your way. Did you try something like this?

mt + facet_grid(cyl ~ ., scales="free")

Solution 2 - R

You can't. See here

You can use facet_wrap instead, which will 'free' both axes

Solution 3 - R

Hopefully, this helps.

mt + facet_wrap(. ~ cyl, scales="free_y")

Solution 4 - R

Try: https://teunbrand.github.io/ggh4x/reference/facet_grid2.html.

This code allows to make the scales of each panel independent using facet_grid, but with facet_grid2.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhatmatrixView Question on Stackoverflow
Solution 1 - RGeorge DontasView Answer on Stackoverflow
Solution 2 - Rjf328View Answer on Stackoverflow
Solution 3 - RCraig ForbesView Answer on Stackoverflow
Solution 4 - RCamilo MontesView Answer on Stackoverflow