气象水文科研猫公众号交流邮箱:leolovehydrometeor@hotmail.com欢迎投稿&批评指正如有侵权且本公众号未能正确引用原文,请联系删除,谢谢理解、谢谢配合。
#openair包绘制泰勒图&热图
原文超链接:
《Python、R和Matlab地图可视化(四)》
#openair包绘制日历图# load example data from packagedata(mydata)# basic plotcalendarPlot(mydata, pollutant = "o3", year = 2003)# show wind vectorscalendarPlot(mydata, pollutant = "o3", year = 2003, annotate = "wd")## Not run:# show wind vectors scaled by wind speed and different colourscalendarPlot(mydata, pollutant = "o3", year = 2003, annotate = "ws",cols = "heat")# show only specific months with selectByDatecalendarPlot(selectByDate(mydata, month = c(3,6,10), year = 2003),pollutant = "o3", year = 2003, annotate = "ws", cols = "heat")# categorical scale examplecalendarPlot(mydata, pollutant = "no2", breaks = c(0, 50, 100, 150, 1000),labels = c("Very low", "Low", "High", "Very High"),cols = c("lightblue", "green", "yellow", "red"), statistic = "max")## End(Not run)
mydata %>% selectByDate(month = c(1,2,3,4,5,6,7,8,9,10,11,12), year = format(Sys.time(),format='%Y')) %>% calendarPlot(breaks = c(0,35,75,115,150,250,300),cols =rev(rainbow(7)), labels = c('优','良','轻度污染','中度污染','重度污染','严重度污染'),pollutant = 'pm25',year = 2020)
日历图往期推文超链接:
1 《R语言日历图(完)》
2 《R语言基础地图构建(9)》
3 《R语言热图(完)》
4 《免费开源Python和R成为科研主流》
5 《R解决之输出pdf矢量图中文乱码(一)》
6 《R语言ggplot2分面(四)》
library(ggplot2)ggplot(mtcars,aes(x=row.names(mtcars), y = disp,fill='red'))+geom_bar(stat = "identity")+theme_bw()+ xlab("cars") + theme(axis.text.x = element_text(angle = 90, vjust = .6, size = 10))ggplot(mtcars,aes(x=row.names(mtcars), y = disp))+geom_bar(stat = "identity")+theme_bw()+ xlab("cars") + theme(axis.text.x = element_text(angle = 90, vjust = .6, size = 10))+coord_flip()ggplot(mtcars,aes(x=row.names(mtcars),y=disp,fill='red'))+geom_bar(stat = "identity")+theme_bw()+ xlab("cars") + theme(axis.text.x = element_text(angle = 90, vjust = .6, size = 10))+coord_flip()
setwd('F:/Rpeng/28')library(ggplot2)#创建模拟数据集set.seed(1234)M Month Region Amount df df$Month #绘制横向的分面图ggplot(data = df, mapping = aes(x = Region, y = Amount, fill = Region)) + geom_bar(stat = 'identity') + facet_wrap(~Month, ncol = 3) + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())+ theme_bw() + # 去除地图灰色背景 theme(panel.grid.major=element_line(colour=NA), panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA), panel.grid.minor = element_blank())+ # 去除地图网格theme(axis.ticks.length=unit(-0.1, "cm"), axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")) )+ theme(axis.text.x = element_text(angle=0,hjust=1), # 旋转坐标轴label的方向 text = element_text(size = 12, face = "bold",family="serif"), panel.spacing = unit(0,"lines") )+ #分面间隔设为零scale_y_continuous(expand = c(0,0)) #这个可以图形去掉与X轴间隙
library(gcookbook)cabbage_expggplot(cabbage_exp,aes(x = Cultivar, y = Weight, fill = Date))+ geom_bar(stat = "identity", position = "dodge")+theme_bw()+ geom_errorbar(data = cabbage_exp, aes(ymin = Weight - se, ymax = Weight + se), width = .4, position = position_dodge(0.9))
library(ggplot2)data1=read.csv( "F:/Rpeng/29/data/test2.csv" ) ggplot(data=data1,mapping=aes(x=obj,y=val,fill=obj,group=factor(1)))+ geom_bar(stat="identity")+theme_bw()ggplot(data=data1,mapping=aes(x=obj,y=val,fill=obj,group=factor(1)))+ geom_bar(stat="identity",width=0.5)+theme_bw()data1ggplot(data=data1,mapping=aes(x=obj,y=val,fill=obj,group=factor(1)))+ geom_bar(stat="identity")+theme_bw()ggplot(data=data1,mapping=aes(x=obj,y=val,fill=obj,group=factor(1)))+theme_bw()+ geom_bar(stat="identity")+geom_text(aes(label = val, vjust = -0.8, hjust = 0.5, color = obj), show.legend = TRUE)
library(ggplot2)mydata=read.csv( "F:/Rpeng/29/data/test1.csv" ) ggplot(mydata,aes(Conpany,Sale,fill=Year))+geom_bar(stat="identity",position="dodge")+theme_bw()
library(ggplot2)dat=read.csv( "F:/Rpeng/29/data/test3.csv" ) ggplot(dat, aes(x = type,y = Num,fill = Sample))+ ####position="stack"堆叠状 geom_bar(stat ="identity",width = 0.6,position ="stack")+ scale_fill_manual(values = c("red","blue"))+ labs(x = "",y = "", title = "test")+theme_bw()+ ####文字标签和geom_bar的参数position一致,同时调整文字位置vjust=0.5 geom_text(aes(label = dat$Num),position=position_stack(vjust =0.5),size = 5)+ guides(fill = guide_legend(reverse = F))+ theme(plot.title = element_text(size = 14,face = "bold", vjust = 0.5, hjust = 0.5), legend.title = element_blank(), legend.text = element_text(size = 14, face = "bold"), legend.position = 'right', legend.key.size=unit(0.8,'cm')) ggplot(dat, aes(x = type,y = Num,fill = Sample))+ ####position="stack" 改为"postion_stack(reverse=T) 反向堆叠 geom_bar(stat ="identity",width = 0.6,position =position_stack(reverse = T))+ scale_fill_manual(values = c("red","blue"))+ labs(x = "",y = "", title = "test")+theme_bw()+ ####文字标签和柱子一样需要反向堆叠 geom_text(aes(label = dat$Num),position=position_stack(reverse =T,vjust =0.5),size = 5)+ guides(fill = guide_legend(reverse = F))+ theme(plot.title = element_text(size =14,face = "bold", vjust = 0.5, hjust = 0.5), legend.title = element_blank(), legend.text = element_text(size =14, face = "bold"), legend.position = 'right', legend.key.size=unit(0.8,'cm'))
library(ggplot2)set.seed(1234)# 从数据集 diamonds中抽取1000个样本diam # 当不做任何设置时,此时的顺序按照变量clarity和color的原始顺序排列ggplot(diam, aes(x = clarity, fill=color)) + geom_bar(stat='count') + geom_bar(stat='count') + labs(x = 'Family Size') + theme_bw()ggplot(diam,aes(x = factor(clarity,levels=c('SI2', 'I1', 'SI1','VS2', 'VS1', 'VVS2', 'VVS1', 'IF')),fill=color))+ geom_bar(stat='count')+ labs(x = 'Family Size') + theme_bw()clardf names(clardf) library(dplyr)clardf ggplot(diam, aes(x = factor(clarity, levels=clardf$clarity),fill=color)) + geom_bar(stat='count') + labs(x = 'Family Size') + theme_bw()ggplot(diam, aes(x = clarity, fill=color)) + geom_bar(stat='count')+ scale_fill_discrete(limits=c('J', 'I', 'H', 'G', 'F', 'D', 'E')) + labs(x = 'Family Size') + labs(fill="color")+theme_bw()
library(tidyverse)library(ggsci)names(iris)# 简单柱形图mpg%>%group_by(drv)%>% summarise(avg=mean(hwy),se=sd(hwy))%>%ggplot(aes(drv,avg,fill='red'))+geom_col(color="black",position="dodge",width=0.3)+ geom_errorbar(aes(ymin=avg,ymax=avg+se),width=0.1)+ geom_text(aes(y=avg+se),label=c("a","b","c"),vjust=-0.5)+theme_bw()
多跑跑大佬们的python源码:
关注气象水文科研猫公众号一起交流学习吧
关注气象水文科研猫公众号一起交流学习吧
只要你点下方【分享】【赞】【在看】
我们就是好朋友,Thanks♪(・ω・)ノ