Home > Software engineering >  pass a list as arguments to ggplot
pass a list as arguments to ggplot

Time:12-17

I would like to pass a list as arguments to ggplot. The solutions I found so far usually use do(), but I don't know how to use that here. In the example below I would like ggplot to take the name and limits argument from the variable.

library(ggplot2)
p<-ggplot(mtcars, aes(x=wt, y=mpg))   
  geom_point()

p

yscale<-list(limits=c(0,40), name='A Y scale name')
p<-p scale_y_continuous(yscale) #how to change this line?
p

CodePudding user response:

Use do.call:

yscale<-list(limits=c(0,40), name='A Y scale name')
p <- p   
  do.call(scale_y_continuous, yscale)
  •  Tags:  
  • r
  • Related