For various reasons I have a data frame that contains a variable with the name
"log(foo)". I am trying to plot objects like this from within a function. I use
aes_string() in my functions to refer to the name of the variable I want to plot, but this is failing when the string is a function call like
"log(foo)". When the data for the plot is evaluated, ggplot is looking for a variable with name
library("ggplot2") df <- data.frame(y = runif(1:10), "log(foo)" = 1:10, check.names = FALSE) varname <- "log(foo)" ggplot(df, aes_string(x = varname, y = "y")) + geom_point()
The above gives the error:
Error in FUN(X[[i]], ...) : object 'foo' not found
Is there any idiom that will allow the use of non standard variable names like this?