目录
R语言之可视化①误差棒
R语言之可视化②点图
R语言之可视化③点图续
R语言之可视化④点韦恩图upsetR
======================================
Python数据处理从零开始----第四章(可视化)(5)(韦恩图)
======================================
个人感想:建议还是用R语言来处理韦恩图,python无论是简易程度或者美观程度都不如R语言 upsetR
正文
介绍一个R包UpSetR,专门用来集合可视化,当多集合的韦恩图不容易看的时候,就是它大展身手的时候了。
原理比较简单,做法大概分为两种,第一种是定义数据集后,画图自动取交集。第二种做法是先取交集,然后画图。绘制韦恩图的目的主要是查看数据集之间的异同。
第一种:定义数据集后直接画图取交集
library(UpSetR)
library(dplyr)
library(tidyr)
rm(list=ls())
diff <- read.csv("diffSig_ttest.csv",header = T,row.names = 1)
加载包和所使用的数据。
AA <- subset(diff, splice_type=="AA")
AD <- subset(diff, splice_type=="AD")
AP <- subset(diff, splice_type=="AP")
AT <- subset(diff, splice_type=="AT")
取出准备取交集的数据集们
#fromList
listinput <- list(AD = AD$symbol,
AP = AP$symbol,
AA = AA$symbol,
AT = AT$symbol)
library(UpSetR)
# pdf(file='upset.pdf',height = 8,width = 8)
p <- upset(fromList(listinput),nsets = 4, order.by = "freq")
# dev.off()
绘制图片
第二种:取交集后在画图
setwd("E:\\Rwork")
library(UpSetR)
require(ggplot2);
require(plyr);
require(gridExtra);
require(grid);
input <- c(
'cancer1'= 1578,
'cancer2' = 1284,
'cancer3' = 2488,
'cancer1&cancer2' =205,
'cancer1&cancer3' = 828,
'cancer2&cancer3' =589,
'cancer1&cancer2&cancer3' =120
)
data <- fromExpression(input)
p1 <- upset(data, nsets = 9,
sets = c('cancer1',
'cancer2' ,
'cancer3'),
keep.order = TRUE,
# number.angles = 30,
point.size = 5,
line.size = 1.3,
mainbar.y.label = "IntersectionSize",
sets.x.label = "",
mb.ratio = c(0.60, 0.40),
text.scale = c(4, 4, 0.5, 0.5,3, 4))
p1
网友评论