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)
In this example, why didn't the points get coloured by x?
Have you tried
ggplot(mpg, aes(displ, hwy, col=as.factor(x))) + geom_point() + facet_wrap(~x)
?I used an example from
ggplot2::facet_wrap
. So, you can easily replace~class
withx
containing a character or a formulae. Example :