rm(list=ls())
library(ggplot2)
library(ggvenn)
library(paletteer)
if(!require(paletteer))install.packages("paletteer")
if(!require(scico))install.packages('scico')
if(!require(nord))install.packages('nord')
# 韦恩图的绘制学习
第一个韦恩图的画法
样例数据
a <- list(Set 1
= c(1, 3, 5, 7, 9),
Set 2
= c(1, 5, 9, 13),
Set 3
= c(1, 2, 8, 9),
Set 4
= c(6, 7, 10, 12))
可视化绘制
opar <- par(family = "Roboto Condensed")
mypal= c('#E31A1CFF', '#FB9A99FF','#6A3D9AFF','#B2DF8AFF')##自定义颜色,选择paletteer的配色
ggvenn(a,
fill_color=mypal,#填充颜色
fill_alpha = .7,##调节透明度
stroke_linetype = "longdash",#调节圈的线条样式:默认是"solid",这里我选择虚线
stroke_color='white',#(线条颜色):默认是"black"
#stroke_alpha(线条透明度):默认是1
#stroke_size(线条宽度):默认是1
set_name_size = 8,#文本名大小
#set_name_color = ,#(文本名颜色):默认是"black"
text_size=5 #文本大小默认是4.
)
可以在下面找到自己的配色
paletteer_c("scico::berlin", n = 10)
## <colors>
#9EB0FFFF #5AA3DAFF #2D7597FF #194155FF #11181DFF #270C01FF #501802FF #8A3F2AFF #C37469FF #FFACACFF
paletteer_d("RColorBrewer::Paired")
## <colors>
## #A6CEE3FF #1F78B4FF #B2DF8AFF #33A02CFF #FB9A99FF #E31A1CFF #FDBF6FFF #FF7F00FF #CAB2D6FF #6A3D9AFF #FFFF99FF #B15928FF
paletteer_dynamic("cartography::green.pal", 5)
## <colors>
## #B8D9A9FF #8DBC80FF #5D9D52FF #287A22FF #17692CFF
另一种韦恩图的画法
if(!require(VennDiagram))install.packages('VennDiagram')
library (VennDiagram)
A <- c("C", "D", "B", "E")
B <- c("C", "E", "B", "A")
C <- c("C", "E", "X", "Y")
venn.diagram(x= list(A = A,B = B,C = C),
filename = "pic.png",
height = 450, width = 450,
resolution =300,
imagetype="png",
col="transparent",
fill=c("green","yellow","darkorchid1"),
alpha = 0.50,
cex=0.45,
cat.cex=0.45)
#输入三个向量,最后一个参数是名字,根据实际情况修改
venn <- function(x,y,z,name,title){
if(!require(VennDiagram))install.packages('VennDiagram')
library (VennDiagram)
venn.diagram(x= list(Aff = x,Bio = y,Mine = z),
imagetype ="tiff",
filename=paste(name,".tiff"),
lwd=1,#圈线粗度
lty=1, #圈线类型
col=c('#0099CC','#FF6666','#FFCC99'), #圈线颜色
fill=c('#0099CC','#FF6666','#FFCC99'), #填充颜色
cat.col=c('#0099CC','#FF6666','#FFCC99'),#A和B的颜色
cat.cex = 1.5,# A和B的大小
rotation.degree = 0,#旋转角度
main = title,#主标题内容
main.cex = 1.5,#主标题大小
cex=1.5,#里面交集字的大小
alpha = 0.5,#透明度
reverse=TRUE)
}
venn(A,B,C)
BiocManager::install('ggVennDiagram')
BiocManager::install('hrbrthemes')
这个适合自己的个性化定制韦恩图
library(ggVennDiagram)
样例数据
genes <- paste("gene",1:1000,sep="")
set.seed(123)
随机抽取基因组成列表的四个元素
x <- list(A=sample(genes,300),
B=sample(genes,525),
C=sample(genes,440),
D=sample(genes,350))
可视化绘制
之后可以个性化定制自己需要的韦恩图
library(ggplot2)
ggVennDiagram(x, category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"),
size=1,lty="longdash",color="gray60") +
scale_fill_gradient(name="Count",low="#EC7D85",high = "#182F6F") +
hrbrthemes::theme_ipsum(base_family = "sans") +
labs(title = "Example of ggVennDiagram:: ggVennDiagram function",
subtitle = "processed charts with ggVennDiagram()",
caption = "Visualization by DataCharm") +
theme(plot.title = element_text(hjust = 0.5,vjust = .5,color = "black",face = 'bold',
size = 20, margin = margin(t = 1, b = 12)),
plot.subtitle = element_text(hjust = 0,vjust = .5,size=15),
plot.caption = element_text(face = 'bold',size = 12),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank())
网友评论