跟著Nature Communications學(xué)作圖:R語(yǔ)言ggplot2畫(huà)世界地圖并用md語(yǔ)法添加文字標(biāo)簽

論文

MiDAS 4: A global catalogue of full-length 16S rRNA gene sequences and taxonomy for studies of bacterial communities in wastewater treatment plants

https://www.nature.com/articles/s41467-022-29438-7

數(shù)據(jù)鏈接

https://figshare.com/articles/dataset/Dueholm2021a_data_zip/16566408/1

代碼鏈接

https://github.com/msdueholm/MiDAS4

今天的推文我們重復(fù)一下論文中的Figure1a 世界地圖

image.png

之前的推文介紹過(guò)世界地圖添加采樣地點(diǎn)

首先是地圖

我這里就不畫(huà)國(guó)家的邊界了,本來(lái)是想添加每個(gè)洲的邊界的,但是暫時(shí)沒(méi)有找到辦法,想到了再來(lái)介紹吧

library(ggplot2)
world<-map_data("world")
ggplot() +
  geom_polygon(data=world,aes(x=long,y=lat,group=group),
               fill="#dedede")+
  theme_bw()+
  scale_y_continuous(expand = expansion(mult=c(0,0)))+
  scale_x_continuous(expand = expansion(add=c(0,0))) -> world.map

world.map

image.png

添加采樣點(diǎn)

df<-read.csv("figure1df.csv")
world.map+
  geom_point(data = df,
             aes(x=Longitude, 
                 y=Latitude, 
                 colour = Process_type2), size=2)+
  scale_color_manual(values = c("#3373a5","#97b1c0",
                                         "#f8ad63",
                                         "#d8191a",
                                         "#c4c4c4"))
image.png

添加文本標(biāo)簽

library(ggtext)                                  
dftext<-data.frame(
  x=c(-180,-150,-10,100,50,-50),
  y=c(40,-50,-50,-50,50,60),
  label=c("**North america**<br>3 countries<br>107 cities<br>145WWTPs",
          "**South american**<br>2 countries<br>29 cities<br>38 WWTPs",
          3,4,5,6)
)
world.map01 +
  theme(legend.position = c(0.9,0.7),
        legend.background = element_rect(fill="transparent"),
        legend.box.background = element_rect(color="gray",
                                             fill="transparent"),
        legend.key = element_rect(fill="transparent"))+
  geom_richtext(data=dftext,
                aes(x=x,y=y,label=label),
                nudge_x =0,hjust=0,
                fill="transparent")
image.png

示例數(shù)據(jù)和代碼可以直接到論文中去獲取 或者給推文點(diǎn)贊,點(diǎn)擊在看,然后留言獲取

歡迎大家關(guān)注我的公眾號(hào)

小明的數(shù)據(jù)分析筆記本

小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1、R語(yǔ)言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡(jiǎn)單小例子;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記;3、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容