错误:ggplot2

时间:2018-02-28 13:59:00

标签: r ggplot2 graph bar-chart

我正在尝试绘制一个使用3个数据集的栏。此条形图,p4,是前3个条形图的摘要,前3个图表有效,其p4是问题。一旦我尝试制作它我得到错误:

错误:stat_bin()不得与y审美

一起使用

我不确定错误是什么,我是r和ggplot2的新手。

代码:

library(ggplot2)

p<-ggplot(data=english, aes(x = reorder(V1, -V3), y=V3))+
  geom_bar(stat="identity", 
           fill="steelblue", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9)) +
  ggtitle("English") +
  theme(plot.title = element_text(hjust = 0.5)) +
  labs(x="Letter", y="Frequency") +
  coord_flip() +
  scale_y_continuous(limits = c(0,max(english[,"V3"])+3)) + 
  geom_text(aes(label=V3), vjust=0.4, hjust=-0.1, size=3.5)

p2<-ggplot(data=french, aes(x = reorder(V1, -V3), y=V3))+
  geom_bar(stat="identity", 
           fill="steelblue", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9)) +
  ggtitle("French") +
  theme(plot.title = element_text(hjust = 0.5)) +
  labs(x="Letter", y="Frequency") +
  coord_flip() +
  scale_y_continuous(limits = c(0,max(french[,"V3"])+3)) + 
  geom_text(aes(label=V3), vjust=0.4, hjust=-0.1, size=3.5)

p3<-ggplot(data=german, aes(x = reorder(V1, -V3), y=V3))+
  geom_bar(stat="identity", 
           fill="steelblue", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9)) +
  ggtitle("German") +
  theme(plot.title = element_text(hjust = 0.5)) +
  labs(x="Letter", y="Frequency") +
  coord_flip() +
  scale_y_continuous(limits = c(0,max(german[,"V3"])+3)) + 
  geom_text(aes(label=V3), vjust=0.4, hjust=-0.1, size=3.5)

p4<-ggplot(aes(x=V1, y=V3))+
  geom_bar(data=english,
           stat="identity", 
           fill="steelblue", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9))+
  geom_bar(data=french,
           stat="identity", 
           fill="green", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9))+
  geom_bar(data=german,
           stat="identity", 
           fill="red", 
           color="black", 
           width = 0.8, 
           position = position_dodge(width = 0.9))+
  ggtitle("Laguages") +
  theme(plot.title = element_text(hjust = 0.5)) +
  labs(x="Letter", y="Frequency")

require(gridExtra)
grid.arrange(p, p2, p3, p4, ncol=2)

0 个答案:

没有答案