r - How do I reference an object name as text in a label for a ggplot? -
basically wish mitigate amount of re-coding have when creating new plots changing reference "xvar" object below...
xvar<-"n_age" ggplot(data=dat4,aes(x=n_age,y=count))+ geom_smooth()+ labs(x=xvar, y="count")
this code works ok in "labs" part of statement (as referencing text) in "aes" component need re-specify n_age. can not use syntax removes quotation marks xvar object, reference object?
thanks, daniel.
you can specify aes_string
instead of aes
:
xvar<-"n_age" ggplot(data=dat4,aes_string(x=xvar,y="count"))+ geom_smooth()+ labs(x=xvar, y="count")
Comments
Post a Comment