ggplot2, facet_grid, free scales?

2020-01-27 03:52发布

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 ggplot2
3条回答
2楼-- · 2020-01-27 04:17

You can't. See here

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

查看更多
祖国的老花朵
3楼-- · 2020-01-27 04:25

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")
查看更多
霸刀☆藐视天下
4楼-- · 2020-01-27 04:26

Hopefully, this helps.

mt + facet_wrap(. ~ cyl, scales="free_y")
查看更多
登录 后发表回答