How to pass column name in ggplot facet_wrap in a function

折月煮酒 提交于 2019-12-02 08:13:44

I used an example from ggplot2::facet_wrap. So, you can easily replace ~class with x containing a character or a formulae. Example :

library(ggplot2)
x="class"#or ~class
ggplot(mpg, aes(displ, hwy)) +
        geom_point() +
        facet_wrap(x)

Have you tried ggplot(mpg, aes(displ, hwy, col=as.factor(x))) + geom_point() + facet_wrap(~x) ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!