R语言画维恩图--ggvenn
2021-07-04 本文已影响0人
MLD_TRNA
install.packages("devtools")
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)
图片.png
这里遇到一个问题是文字标签超出边界了,如何调节文字标签的位置暂时还不知道如何通过代码实现,只能出图后手动编辑了。
接下来是美化
比如改变配色,去掉百分比,更改文字的颜色等等
ggvenn(x,
show_percentage = F,
stroke_color = "white",
fill_color = c("#ffb2b2","#b2e7cb","#b2d4ec","#d3c0e2"),
set_name_color = c("#ff0000","#4a9b83","#1d6295","#7030a2"))
图片.png
接下来是再画一个三维的韦恩图
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"))
图片.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",""))
图片.png