我不明白为什么,但似乎有什么奇怪的与for
循环。下面的代码运行良好。但是当我尝试使用for
循环时,仅添加了最后的geom_bar
。
TPlot = ggplot() +
geom_bar(aes(x = 1:3, y=c(1,1,1), width=0.1),stat="identity", alpha=0.2,
position="identity") +
xlab("x") +
ylab("y")
TPlot = TPlot + geom_bar(aes(x = 1:3, y = c(2,2,2), width=0.1),
stat="identity", position="identity", alpha=0.2)
TPlot = TPlot + geom_bar(aes(x = 1:3, y = c(3,3,3), width=0.1),
stat="identity", position="identity", alpha=0.2)
TPlot
随着for
循环。
TPlot = ggplot() +
geom_bar(aes(x = 1:3, y=c(1,1,1), width=0.1),stat="identity", alpha=0.2,
position="identity") +
xlab("x") +
ylab("y")
for (i in 2:3){
TPlot = TPlot + geom_bar(aes(x = 1:3, y = c(i,i,i), width=0.1),
stat="identity", position="identity", alpha=0.2)
}
TPlot
此代码的工作。这导致了第一张照片的一张照片。感谢乔兰。
TPlot = ggplot() +
geom_bar(aes(x = 1:3, y=c(1,1,1), width=0.1),stat="identity", alpha=0.2,
position="identity") +
xlab("x") +
ylab("y")
for (i in c(2,3)){
TPlot = TPlot + geom_bar(data=data.frame(x = 1:3, y = c(i,i,i)),
aes(x=x, y=y, width=0.1),
stat="identity", alpha=0.2)
}
TPlot
您设置了'position =“identity”'? – joran
不,这不适合我。我会提供更多的代码,坚持下去。 –
'position =“identity”'正在工作,但其他事情却出错了,可能与你在'aes()'里面做的所有非标准(和不明智)事情有关。 – joran