这很奇怪——我想?
library(ggplot2)
tf <- which(sapply(diamonds, is.factor))
diamonds.tf <- diamonds[,tf]
到现在为止还挺好。但接下来的麻烦来了:
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)
}
这会将绘图保存在我的工作目录中 - 但 x-label 错误。我认为这很奇怪,因为直接调用 ggplot 会产生正确的情节:
i <- 2
ggplot(diamonds, aes(x=diamonds[,i]))+geom_bar()+xlab(names(diamonds)[i])
我真的不知道如何将其描述为一个合适的标题 - 关于更具描述性的问题标题的建议是最受欢迎的。
提前致谢