ggplot2绘制采样地,手动批量指定颜色、性状、大小、设置图例

 

001、原始数据

复制代码
Longitude   Latitude    diqu    subspe  num
-104    39  West_Europe Bos_taurus  10
-3  56  West_Europe Bos_taurus  30
-3  51  West_Europe Bos_taurus  20
2   -44 Central_South_Europe    Bos_taurus  26
2   45  Central_South_Europe    Bos_taurus  22
3   51  West_Europe Bos_taurus  20
5   43  Central_South_Europe    Bos_taurus  20
7   45  Central_South_Europe    Bos_taurus  8
7   46  Central_South_Europe    Bos_taurus  30
12  49  Central_South_Europe    Bos_taurus  23
29  1   Africa  Bos_taurus_Bos_indicus  17
36  3   Africa  Bos_taurus_Bos_indicus  5
44  36  The_Middle_East_Northwest_China Bos_taurus_Bos_indicus  8
70  -20 India_Paksitan  Bos_indicus 10
71  30  India_Paksitan  Bos_indicus 4
75  32  India_Paksitan  Bos_indicus 20
77  28  India_Paksitan  Bos_indicus 5
80  43  Northwest_China Bos_taurus  11
87  43  Northwest_China Bos_taurus  30
90  38  Northwest_China Bos_taurus  5
复制代码

 

002、绘图

复制代码
library(ggplot2)
library(ggthemes)

mymap <- read.table("distri.txt", header =T)
head(mymap)

world <- map_data("world")

my_fill = c("Africa"="#984EA3","India_Paksitan"="#F781BF","South_China"="#E41A1C",
            "Central_South_Europe"="#FFFF33","Northeast_Asia"="#FF7F00",
            "Northwest_China"="#98F5FF","Tibet"="#377EB8","West_Europe"="#4DAF4A",
            "North_Central_China"="#000000","The_Middle_East_Northwest_China"="#000000")
my_shape = c("Bos_taurus"=23,"Bos_indicus"=21,"Bos_taurus_Bos_indicus"=19)


p1 <- ggplot(world, aes(long, lat)) +
  geom_map(map=world, aes(map_id=region), fill="#DEDEDE", color=NA) +
  xlim(-105, 135)+ ylim(-50, 60)+
  coord_quickmap()  

p2 <- p1 + geom_point(data=mymap, color='black',
                      aes(x = Longitude, y = Latitude, 
                          size=num, shape=subspe, fill=diqu))+
  scale_fill_manual(values = my_fill)+
  scale_shape_manual(values = my_shape)+
  theme_map()+
  theme(legend.position=c(0,-0.1),legend.justification=c(0,0), # 图例位置
        legend.background=element_blank(), # 去除图例背景
        legend.title=element_blank(),  # 去除图例标题
        legend.text = element_text(size=10), # 图例文本大小
        legend.key=element_rect(color=NA, fill=NA))+ # 去除图例形状周围的背景
  
  # 修改图例形状、大小
  guides(fill=guide_legend(override.aes=list(size=5,shape=21)),
         shape = guide_legend(override.aes = list(size=5, sahpe=my_shape)))

p2
复制代码

 

 

 

 

绘图结果如下:

 。

 

origin:

01、https://www.jianshu.com/p/6f0639b98017

 

posted @   小鲨鱼2018  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-06-23 python 中 Bio中SeqIO模块处理fastq数据
2023-06-23 linux 中shell脚本实现统计每一个read的长度
2023-06-23 Source distributions 和 Binary distributions:
2023-06-23 Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
2023-06-23 CMake Error at /root/anaconda3/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake:9 (message): Failed to fi
2023-06-23 -- Checking for curses support - Failed
2023-06-23 -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system vari
点击右上角即可分享
微信分享提示