在地图上加入直方图

来源:互联网 发布:java的弱引用 编辑:程序博客网 时间:2024/06/16 04:04
library(mapproj)library(ggplot2)library(readxl)library(plyr)#Reading boundary data from provinceschina_map <- readShapePoly("C:\\Users\\Administrator\\Desktop\\dt\\bou2_4p.shp")#Change projection modeggplot(china_map,aes(x=long,y=lat,group=group))+       geom_polygon(fill="white",colour="grey")+       coord_map("polyconic")#Loading and stitching administrative informationx <- china_map@data                                    xs <- data.frame(x,id=seq(0:924)-1)                     china_map1 <- fortify(china_map)                        china_map_data <- join(china_map1, xs, type = "full")   #Read business indicators, merge with geographic dataczh <- read_excel("C:/Users/Administrator/Desktop/czh.xlsx")czh_1 <- read_excel("C:/Users/Administrator/Desktop/czh_1.xlsx")china_map_data$NAME <- as.character(china_map_data$NAME)china_data <- join(china_map_data, czh, type="full")china_data$group <- as.character(china_data$group)#Mappingggplot()+geom_polygon(aes(x=long, y=lat,group=group,fill=高血压),data=china_data,colour="grey60")+  scale_fill_gradient(low="white",high="steelblue") +   #Call color gradient  geom_errorbar(data=czh_1,aes(x=x-0.5,ymin=y,ymax=y+0.7*no/max(no,yes)*5),                size=3,color="red",width=0,alpha=0.8)+       geom_errorbar(data=czh_1,aes(x=x+0.5,ymin=y,ymax=y+0.7*yes/max(no,yes)*5),                size=3,color="green",width=0,alpha=0.8)+  geom_text(aes(x=x,y=y-0.6,label=paste0(czh_1$NAME,ifelse(Ratio>0,"▲","▼"),Ratio)),            data=czh_1,family="myFont",size=2.5)+      #Add name and symbol of province  annotate("text", x=130, y=20, label="● 省内流动", color= "red", size=5)+   annotate("text", x=130, y=17, label="● 跨省流动", color= "green", size=5) #+  #ggtitle("xxxxxxxxxxx")   #说明:如要加标题,去掉#即可!

这里写图片描述

原创粉丝点击