首页 文章

在R中具有不同变量的条形图旁边的多个

提问于
浏览
1

我在R中有三个这样的列表;

> list1<-list(Joseph=12, Johan=10, Dave=15,Steve=3,Jo=8)
> list2<-list(Joseph=12, David=10,George=2,Damian=20,Louis=2)
> list3<-list(Bill=22,David=2,Peter=2,Dave=18,Sebastian=8,William=3)

每列都有一个名称标签和一个数字分数 .

我想要显示3个条形图,一个在另一个旁边;每个条形图绘制每个列表的3个主要得分名称,保存标签 .

例如,第一个条形图显示Dave,Joseph,Johan,高度为15,12,10 . 第二个条形图显示Damian,Joseph和David的高度为20,12和10,而第三个条形图显示Bill,Dave,Sebastian的高度为22,18和8 .

我发现只有一些例子,在不同的实验中,相同的变量被绘制在一个旁边的多个条形图中,但这里名义上的变量可能会从一个条形图变为另一个 .

如何实现我的目标?

2 回答

  • 4

    使用link中给出的多色时功能 . 我也在使用ggplot2和reshape2:

    p1<-ggplot(melt(data.frame(list1)),aes(x=variable,y=value))+geom_bar(stat='identity')
    p2<-ggplot(melt(data.frame(list2)),aes(x=variable,y=value))+geom_bar(stat='identity')
    p3<-ggplot(melt(data.frame(list3)),aes(x=variable,y=value))+geom_bar(stat='identity')
    multiplot(p1, p2, p3, cols=1)
    

    另一种选择是在gridExtra包中使用grid.arrange():

    grid.arrange(p1, p2,p3,ncol=3)
    

    enter image description here

  • 3

    你可以使用 parmfcol / mfrow

    par(mfcol=c(1,3))
    barplot(unlist(list1))
    barplot(unlist(list2))
    barplot(unlist(list3))
    par(mfcol=c(1,1))
    

    enter image description here

相关问题