grouped bar graph

女生的网名这么多〃 提交于 2019-11-28 06:02:55
George Dontas

Here is a classic solution. (Supposing your dataframe is named df )

data <- tapply(df$total_dist, list(df$groupname,df$bin), sum)  barplot(data,beside=T,col=c("#ee7700","#3333ff") ,main="European Parliament Elections",xlab="Group",ylab="Seats")  legend(locator(1),rownames(data),fill=c("#ee7700","#3333ff")) 

and here is solution using ggplot2

library(ggplot2) qplot(factor(bin),data=df,geom="bar",fill=groupname,weight=total_dist,position="dodge", main = "European Parliament Elections", xlab="Group",ylab="Seats") 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!