I'm writting a function that needs to be able to map a user specified mapping to a user supplied data.frame, so it's not up to me to give the columns sensible names.
How can the call be made to map to a column named log(y)?
I thought this would be a case for aes_string but this doesn't work.
library(ggplot2)
df <- data.frame(
gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30)
)
names(df)[2] <- "log(y)"
ggplot(df, aes_string("gp", "log(y)")) +
geom_point()
#> Error in FUN(X[[i]], ...): object 'y' not found
Created on 2019-03-12 by the reprex package (v0.2.1)
I also tried quotations but couldn't get it to work and I'm not sure whether this would be the right application...
I also cannot map the column by df$'log(y)' since within my function the plot call is evaluated on two different data sets, both containing a log(y) column.
Any help would be greatly appreciated. Thanks.