您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關R語言畫韋恩圖后拼圖的示例分析,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
今天要模仿的圖片來自于論文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology
重復的圖片是Figure2中的韋恩圖,然后將兩個韋恩圖拼到一起
R語言里比較常用的畫韋恩圖的包是VennDiagram
,但是今天的內容涉及到拼圖,用VennDiagram
畫圖后如何拼圖我暫時還不知道。所以今天使用另外一個包ggvenn
,因為是gg系列,拼圖實現起來就相對比較容易。之前也錄制過視頻介紹這個包
devtools::install_github("yanlinlin82/ggvenn")
輸入數據可以是列表,也可以是一個數據框,今天用列表的形式作為輸入數據
df1<-read.csv("example_data/venn_example_1.csv",header=T)
df2<-read.csv("example_data/venn_example_2.csv",header=T)
df3<-read.csv("example_data/venn_example_3.csv",header=T)
df4<-read.csv("example_data/venn_example_4.csv",header=T)
x<-list(`High marine protein`=df1$A,
`Medium fat`=df2$B,
`High fat`=df3$C,
`Low marine protein`=df4$D)
library(ggvenn)
ggvenn(x)
這里遇到一個問題是文字標簽超出邊界了,如何調節文字標簽的位置暫時還不知道如何通過代碼實現,只能出圖后手動編輯了。
比如改變配色,去掉百分比,更改文字的顏色等等
ggvenn(x,
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec","#d3c0e2"),
set_name_color = c("#ff0000","#4a9b83","#1d6295","#7030a2"))
ggvenn(x,
c("Medium fat","High fat", "Low marine protein"),
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec"),
set_name_color = c("#ff0000","#4a9b83","#1d6295"))
因為是gg系列,拼圖可以選擇的就很多了,這里我選擇cowplot
這個包
p1<-ggvenn(x,
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec","#d3c0e2"),
set_name_color = c("#ff0000","#4a9b83","#1d6295","#7030a2"),
set_name_size = 2)
p2<-ggvenn(x,
c("Medium fat","High fat", "Low marine protein"),
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec"),
set_name_color = c("#ff0000","#4a9b83","#1d6295"),
set_name_size = 2)
library(cowplot)
plot_grid(p1,p2,ncol=2,nrow = 1,labels = c("b",""))
上述就是小編為大家分享的R語言畫韋恩圖后拼圖的示例分析了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。