跟著Nature Communications學作圖:R語言ggplot2散點圖及添加文字標簽

論文

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ù)一下論文中的Figure4a

image.png

論文中沒有直接提供這個作圖數(shù)據(jù),需要運行一系列代碼獲得,這里我不介紹前面獲取作圖數(shù)據(jù)的代碼了,感興趣的可以自己去找來代碼試試,如果運行的話需要比較大的內(nèi)存

作圖數(shù)據(jù)部分截圖

image.png

讀取數(shù)據(jù)

library(ggrepel)
library(tidyverse)
library(ggplot2)
library(ggtext)
library(ggrepel)

gV134<-read_csv("fig4a.csv")

作圖代碼

p <- ggplot(gV134, 
            aes_string(x = "V13_mean_abundance", 
                       y= "V4_mean_abundance", 
                       fill="Bias"),
            color="black") + 
  geom_point(size = 2,shape=21) +
  geom_abline(size = 0.5) +
  geom_text_repel(data = 
              filter(gV134, 
                     gV134$FC>1 & gV134$V4_mean_abundance>0.1), 
            aes(label = Genus), 
            #vjust = 1.5, 
            colour="grey30") +
  geom_text_repel(data = 
              filter(gV134, 
                     gV134$FC<(-1) & gV134$V13_mean_abundance>0.1), 
            aes(label = Genus), 
            #vjust = 1.5, 
            colour="grey30") +            
  xlab("Mean V13 amplicon genus read abundance (%)") + 
  ylab("Mean V4 amplicon genus read abundance (%)") +
  scale_x_log10(limits=c(0.001,2)) +
  scale_y_log10(limits=c(0.001,2)) +
  theme_bw() +
  theme(legend.position = "none",
        plot.title = element_markdown())+
  scale_fill_manual(values = c('Equally detected'="#898989",
                                'More abundant with V1-V3'="#2a7cb6",
                                'More abundant with V4'="#d41b21"))+
  labs(title="352 genera equally abundant <span style = 'color:#898989;'>(gray)</span><br/>
       112 genera more abundant with V4 <span style = 'color:#d41b21;'>(red)</span><br/>
       111 genera more abundant with V1-V3 <span style = 'color:#2a7cb6;'>(blue)</span>")
  
  
p
image.png

這里遇到的問題是添加的文本標簽有點多,彼此之間會有重疊,使用ggrepel這個R包也調(diào)節(jié)不出比較好的效果,只能出圖后再編輯圖片了

這里標題的文本只有一部分添加了顏色,可以借助ggtext這個R包的markdown語法實現(xiàn)

示例數(shù)據(jù)和代碼可以自己到論文中下載

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

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

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

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

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

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