本文介绍了如何在函数中的ggplot facet_wrap中传递列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过ggplot facet_wrap或函数中的fill/color传递数据框的列名?我抬头懒洋洋地抬头,却没找到办法.
How to pass column name of a data frame in ggplot facet_wrap or fill/colour in a function? I looked up lazyeval but didn't figure out a way.
x="class"
ggplot(mpg, aes(displ, hwy, col=x)) + geom_point() + facet_wrap(x)
在此示例中,为什么点没有被x着色?
In this example, why didn't the points get coloured by x?
推荐答案
我使用了ggplot2::facet_wrap
中的示例.因此,您可以轻松地用包含字符或公式的x
替换~class
.例子:
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)
这篇关于如何在函数中的ggplot facet_wrap中传递列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!