R柱状图,叠图(排序)

时间:2021-09-25 05:57:45
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