If the column names of a data.frame
are started with numbers, or have spaces, aes_string()
fails to handle them:
foo=data.frame(\"1
As far as I can tell, this method should work programmatically:
foo=data.frame("1st Col"=1:5, "2nd Col"=5:1, check.names=F)
#Save the colnames
bar=colnames(foo)
#change the names to something usable
names(foo) <- c("col1", "col2")
#Plot with arbitrary labs
ggplot(foo, aes(x=col1, y=col2)) + geom_point()+
labs(x=bar[1], y=bar[2])