这期内容当中小编将会给大家带来有关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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。