I have a function:
vis = function(df, x){
p1 <- ggplot(df, aes(x)) + geom_line(aes(y = v2))
p1
}
I have a data frame:
df = data.frame(v0 = c(1,2,3), v1 = c(2,3,4), v2 = c(3,4,5))
I want to generate plot: (1) v2 v.s. v0, (2) v2 v.s. v1.
So I tried:
vis(df, v0) // not work
vis(df, v1) // not work
vis(df, "v0") // not work
vis(df, "v1") // not work
Much appreciated any idea!
Another method using
quo_name
andaes_string
. This does not require dev version ofggplot2
:If we are passing an unquoted string, then convert it to quosure and then evaluate (
!!
)If we pass
x
as strings, then replaceaes
withaes_string
You can use the the name of the column: