R柱状图,叠图(排序)

来源:互联网 发布:淘宝买家秀怎么点赞 编辑:程序博客网 时间:2024/05/18 20:13
each<-read.csv("C:\\Users\\Administrator\\Desktop\\R\\数据三\\eachcl.csv")


cl<-colMeans(each)


clname<-variable.names(each)

#取变量名

cl<-as.numeric(cl)
mycolorscl <- c(heat.colors(11)[1:11])
barplot(cl[sort.list(cl,decreasing=T)[10:1]],names.arg=clname[sort.list(cl,decreasing=T)[10:1]],xlab="city",ylab="value",

        main="空气污染指数",col=mycolorscl[10:1],border=mycolorscl[10:1],ylim = c(0,70))


#sort.list取排序位置



叠图:(ggpl0t)

#叠图:
allend<-read.csv("C:\\Users\\Administrator\\Desktop\\R\\数据三\\allend.csv")
allggplot<-allend[2:4]
for (i in 1:9) {
  test<-allend[(3*i+2):(3*i+4)]
  colnames(test)<-c("how","quanty","city")
  allggplot<-rbind(allggplot,test)
}
p1=ggplot(allggplot,aes(x=city,fill=how))+geom_bar(position="stack")+labs(title="各城市空气质量",y="天数")+theme(plot.title = element_text(size=20,face = "bold",hjust = 0.7))
p1

0 0
原创粉丝点击