How do you wade through the eval()
, parse()
and other-function swamp? This should be straightforward, thus I omit the data.
Original code, with attributes in the data set and a workaround for the chart title.
require(ggplot2)
ggplot(data = qs) + geom_bar(aes(x = G74_Q0005b)) +
ggtitle(attr(qs, "variable.labels")[grep("G74_Q0005b", names(qs))])
Here is a function that simply passes the variable name:
plot.label <- function(var){
ggplot(data = qs) + geom_bar(aes(x = var)) +
ggtitle(attr(qs, "variable.labels")[grep(var, names(qs))])
}
But obviously var
alone is not enough and I am no programmer.
Possibly related?