I'm try to make bar charts over a list of variables. I can get plots. But I want each plot has a title using its variable name, so that I can identify which variables are using in the plot. And the same thing for the legend.I tried the function as.character(), and as.name() to get their names. But they does no work. I don't know how to retrieve their variable names. The similar problems occurs in my second lappy function.My codes follow:
varlist1=c(name[11:40)
ev="aff"
lapply(varlist1, function(nm)
{
q1=ggplot(data,aes(fill=data[[as.name(nm)]],x=aff))
q1+geom_bar(stat="count",position="dodge")+theme_bw()+
ggtitle(as.character(data[[nm]]),"By Aff")
})
lapply(varlist1, function(nm)
{
table(data[[as.name(nm)]], data[[ev]])
})
Thank you very much!!