I want to scale my y-var by multiplying it by a number, say 10, in ggplot. The problem is this is in a Shiny app and the variable must be passed as a character string, i.e. input$variable
.
How can I multiply one of the variables in aes_string()
the same way I would in aes()
? Here is an example of when it fails:
library(ggplot2)
ggplot(data = subset(mtcars, cyl == 4), aes_string(x = "wt", y = "mpg")) +
geom_line(size = 1.5, color = "#00868B") +
geom_line(data = subset(mtcars, cyl == 8), aes_string(x = "wt", y = "mpg" * 10))
Error in "mpg" * 10 : non-numeric argument to binary operator