ggplot画中国地图系列
程序员文章站
2022-03-13 16:49:17
...
好久没写博客的我感觉生锈了…
ggplot画中国地图系列
好久没有用R,有点忘了,最近要画地图,做个小日志~
1. 装R
2. 装RStudio
RStudio网址
之前卸软件一时爽,现在重装软件火葬场…
3. 下载ggplot、ggrepel包
4. 编码
Sys.setlocale(category = "LC_ALL",local="chinese")
library(ggplot2)
library(ggrepel)
ggplot(china_map_data,aes(x=long,y=lat))+
geom_polygon(aes(group=group,fill=ratio),colour="grey")+
scale_fill_gradientn(colors =("#1e90ff","#2ed573","#ff5f40","#fff591"),guide = F)+
coord_map("polyconic")+ #不加coord_map()函数的话,图形会有点扁,coord_map("polyconic")将球面图形映射为平面图
geom_point(aes(x=lon,y=lat,color=color),data = map2116,shape = 17,size = 3)+
geom_text(aes(x=x,y=y,label=name),data=label,size=5,fontface="bold",family="sans")+
geom_text_repel(aes(x=lon,y=lat,label=city),data = mapdta_longanlat,size=2.65)+
scale_colour_hue( name = "Species", labels = c("S.galilaeus", "S.scabieis",'S. acidiscabies','Other Samples'))+
theme(
panel.grid = element_blank(),
panel.background = element_blank(),
panel.border = element_rect(linetype = "solid", fill = NA),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
legend.position=c(.15,0.25),
legend.box.margin = margin(6, 1, 6, 6),
legend.margin = margin(r=35),
legend.box.background = element_rect(colour ="darkblue"),
legend.key = element_rect(fill = "white"))