R

R可视化:ggplot语法的Venn 图

2021-03-08  本文已影响0人  生信学习者2

在进行组间比较的适合,我们常常会使用Venn图展示,常用的Venn R包有gplots、venneuler、VennDiagram等,但是都不怎么适合ggplot语法,现在有基于ggplot开发的ggVennDiagram和ggvenn包更适合可视化Venn图。更多知识分享请到 https://zouhua.top/

安装R包

if (!require(devtools)) install.packages("devtools")
devtools::install_github("gaospecial/ggVennDiagram")
library(ggVennDiagram)

if (!require(devtools)) install.packages("devtools")
devtools::install_github("yanlinlin82/ggvenn")
library(ggvenn)

构造数据

set.seed(20190708)
genes <- paste("gene",1:1000,sep="")
x <- list(
  A = sample(genes,300), 
  B = sample(genes,525), 
  C = sample(genes,440),
  D = sample(genes,350)
  )

ggVennDiagram

四组

ggVennDiagram(x)
ggVennDiagram(x, label_alpha = 0)
ggVennDiagram(
  x, label_alpha = 0,
  category.names = c("Stage 1","Stage 2","Stage 3", "Stage4")
  ) +
  ggplot2::scale_fill_gradient(low="blue",high = "yellow")

三组

ggVennDiagram(x[1:3], label_alpha = 0)

两组

ggVennDiagram(x[1:2], label_alpha = 0)

ggvenn

四组

ggvenn(x)
names(x) <- c("Stage 1","Stage 2","Stage 3", "Stage4")
ggvenn(
  x, 
  fill_color = c("#0073C2FF", "#EFC000FF", "#868686FF", "#CD534CFF"),
  stroke_size = 0.5, set_name_size = 4
  )

三组

ggvenn(
  x, columns = c("Stage 1", "Stage 2", "Stage 3"),
  stroke_size = 0.5
  )

两组

ggvenn(
  x, columns = c("Stage 1", "Stage 2"),
  stroke_size = 0.5
  )

参考

  1. ggVennDiagram

参考文章如引起任何侵权问题,可以与我联系,谢谢。

上一篇下一篇

猜你喜欢

热点阅读