ggplot2-R错误:stat_count()不能与y字符一起使用
我已经检查了以下问题: 不幸的是,这对我没有帮助 我有一个包含4列的数据框: 截止值、震级(系数) TP,SD_TP(变量) (这只是数据帧的一部分) 我正在使用以下代码:ggplot2-R错误:stat_count()不能与y字符一起使用,r,ggplot2,R,Ggplot2,我已经检查了以下问题: 不幸的是,这对我没有帮助 我有一个包含4列的数据框: 截止值、震级(系数) TP,SD_TP(变量) (这只是数据帧的一部分) 我正在使用以下代码: dodge <- position_dodge(width=0.9) gg <- ggplot(barTP, aes(x=CutOff, y=TP, fill=Magnitude)) + theme(plot.title = element_text(size=30))+
dodge <- position_dodge(width=0.9)
gg <- ggplot(barTP, aes(x=CutOff, y=TP, fill=Magnitude)) +
theme(plot.title = element_text(size=30))+
geom_bar(aes(colour = Magnitude))+
scale_fill_manual(values=c("green", "yellow", "orange","red"))+
labs(title = TITOLO,size=20)+
scale_y_continuous(name = "total TPs",breaks = c(0,2,4,6,8,10,12,13), limits = c(-0.5, 14))+
geom_bar(position=position_dodge(), stat="identity") +
geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)+
theme(legend.text=element_text(size=15))+
theme(legend.title=element_text(size=15))+
theme(axis.text.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=.5,face="plain"),
axis.text.y = element_text(colour="gray0",size=15,angle=0,hjust=1,vjust=0,face="plain"),
axis.title.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=0,face="plain"),
axis.title.y = element_text(colour="gray0",size=15,angle=90,hjust=.5,vjust=.5,face="plain"))
奇怪的是,两天前它还有效!现在,同样使用相同的数据帧,它不起作用
我没有更改代码中的任何内容。我刚刚通过dropbox与另一台PC共享了代码。但我不认为这是原因
在@aosmith的建议之后,我将stat=“identity”
放在每个geom\u栏中。
只有在我将R上传到3.2.5版(“非常非常安全的碟片”)并再次安装ggplot2
后,它才起作用
gg <- ggplot(barTP, aes(x=CutOff, y=TP, fill=Magnitude)) +
theme(plot.title = element_text(size=30))+
geom_bar(aes(colour = Magnitude),stat="identity")+
scale_fill_manual(values=c("green", "yellow", "orange","red"))+
labs(title = TITOLO,size=20)+
scale_y_continuous(name = "total TPs",breaks = c(0,2,4,6,8,10,12), limits = c(-0.5, 14))+
geom_bar(position=position_dodge(), stat="identity") +
geom_bar(position=dodge, stat="identity") +
geom_errorbar(limits, position=dodge, width=0.25,stat="identity")+
theme(legend.text=element_text(size=15))+
theme(legend.title=element_text(size=15))+
theme(axis.text.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=.5,face="plain"),
axis.text.y = element_text(colour="gray0",size=15,angle=0,hjust=1,vjust=0,face="plain"),
axis.title.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=0,face="plain"),
axis.title.y = element_text(colour="gray0",size=15,angle=90,hjust=.5,vjust=.5,face="plain"))
plot(gg)
gg在您链接到的问题中,您有多个geom_bar
调用,但只在其中一个调用中放入stat=“identity”
。将stat=“identity”
全部放入,或将它们合并为一个geom_bar
调用。谢谢@aosmith,但不,它仍然不起作用。你建议我更新R-studio吗?我已经尝试再次安装ggplot,但没有任何新情况发生。为什么要添加geom_bar
三次(两次闪避,一次未闪避)?似乎只有一层,例如,geom\u bar(aes(color=magnity),stat=“identity”,position=“dodge”)
会给你想要的。你是对的。我在互联网上参考了一些例子,并将每个部分结合起来。顺便说一句,在以前的版本中,它运行得很好。正如在您链接到的问题中一样,您有多个geom_bar
调用,但只在其中一个调用中放入stat=“identity”
。将stat=“identity”
全部放入,或将它们合并为一个geom_bar
调用。谢谢@aosmith,但不,它仍然不起作用。你建议我更新R-studio吗?我已经尝试再次安装ggplot,但没有任何新情况发生。为什么要添加geom_bar
三次(两次闪避,一次未闪避)?似乎只有一层,例如,geom\u bar(aes(color=magnity),stat=“identity”,position=“dodge”)
会给你想要的。你是对的。我在互联网上参考了一些例子,并将每个部分结合起来。顺便说一下,在以前的版本中,它运行得很好。
Error: stat_count() must not be used with a y aesthetic.
gg <- ggplot(barTP, aes(x=CutOff, y=TP, fill=Magnitude)) +
theme(plot.title = element_text(size=30))+
geom_bar(aes(colour = Magnitude),stat="identity")+
scale_fill_manual(values=c("green", "yellow", "orange","red"))+
labs(title = TITOLO,size=20)+
scale_y_continuous(name = "total TPs",breaks = c(0,2,4,6,8,10,12), limits = c(-0.5, 14))+
geom_bar(position=position_dodge(), stat="identity") +
geom_bar(position=dodge, stat="identity") +
geom_errorbar(limits, position=dodge, width=0.25,stat="identity")+
theme(legend.text=element_text(size=15))+
theme(legend.title=element_text(size=15))+
theme(axis.text.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=.5,face="plain"),
axis.text.y = element_text(colour="gray0",size=15,angle=0,hjust=1,vjust=0,face="plain"),
axis.title.x = element_text(colour="gray0",size=15,angle=0,hjust=.5,vjust=0,face="plain"),
axis.title.y = element_text(colour="gray0",size=15,angle=90,hjust=.5,vjust=.5,face="plain"))
plot(gg)