一个图中有两个条形图和一个线图

时间:2018-01-07 23:11:43

标签: r ggplot2

我想在ggplot中使用两个条形图和一个线图。

我检查了以下代码,但没有工作

 df1<- data.frame(x=c(1:5), y=c(10,20,30,24,44))
 df2<- data.frame(x=c(1:5), y=c(9,25,22,24, 25))
 df3<- data.frame(x=c(1:5), y=c(10,20,30,24,44))

  ggplot()+
  geom_bar(data=df1, aes(x=x, y=y), stat = "identity", position=position_dodge())+
 geom_bar(data=df2, aes( y=y), stat="identity", position=position_dodge())+ 
 geom_line(data=df3, aes(x=x, y=y))

任何帮助将不胜感激。 阿巴斯

1 个答案:

答案 0 :(得分:0)

首先,你需要把数据= ..,x = ..等等&#39;在ggplot中然后是+ geom_bars和lines。

http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_(ggplot2)/

e.g。

ggplot(data=df1, aes(x=x, y=y)) +
  geom_bar(stat = "identity", position=position_dodge())