This is strange - I think?
library(ggplot2)
tf <- which(sapply(diamonds, is.factor))
diamonds.tf <- diamonds[,tf]
So far so good. But next comes the trouble:
pl.f <- ggplot(diamonds.tf, aes(x=diamonds.tf[,i]))+
geom_bar()+
xlab(names(diamonds.tf[i]))
for (i in 1:ncol(diamonds.tf)) {
ggsave(paste("plot.f",i,".png",sep=""), plot=pl.f, height=3.5, width=5.5)
}
This saves the plots in my working directory - but with the wrong x-label. I think this is strange since calling ggplot directly produces the right plot:
i <- 2
ggplot(diamonds, aes(x=diamonds[,i]))+geom_bar()+xlab(names(diamonds)[i])
I don't really know how to describe this as a fitting title - suggestions as to a more descriptive question-title is most welcome.
Thanks in advance