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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -