image.png
重复的图片是Figure2中的韦恩图,然后将两个韦恩图拼到一起
R语言里比较常用的画韦恩图的包是VennDiagram
,但是今天的内容涉及到拼图,用VennDiagram
画图后如何拼图我暂时还不知道。所以今天使用另外一个包ggvenn
,因为是gg系列,拼图实现起来就相对比较容易。之前也录制过视频介绍这个包
第一次使用需要先安装
代码语言:javascript复制devtools::install_github("yanlinlin82/ggvenn")
输入数据可以是列表,也可以是一个数据框,今天用列表的形式作为输入数据
读入数据
代码语言:javascript复制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)
构造一个列表数据
代码语言:javascript复制x<-list(`High marine protein`=df1$A,
`Medium fat`=df2$B,
`High fat`=df3$C,
`Low marine protein`=df4$D)
最基本的韦恩图
代码语言:javascript复制library(ggvenn)
ggvenn(x)
image.png
这里遇到一个问题是文字标签超出边界了,如何调节文字标签的位置暂时还不知道如何通过代码实现,只能出图后手动编辑了。
接下来是美化
比如改变配色,去掉百分比,更改文字的颜色等等
代码语言:javascript复制ggvenn(x,
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec","#d3c0e2"),
set_name_color = c("#ff0000","#4a9b83","#1d6295","#7030a2"))
image.png
接下来是再画一个三维的韦恩图
代码语言:javascript复制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"))
image.png
接下来是拼图
因为是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",""))
image.png