R绘图:配对样本差异表达作图ggpubr

R绘图往期回顾:

R绘图:唱一半的歌,画一半的图 gghalves

R绘图:gggibbous,基于ggplot2的Moon charts

R绘图:ggeconodist,基于ggplot2的另类箱图

R语言学习系列之“多变的热图”

蚂蚁金服在线可视化引擎 G2

R绘图:无与伦比的华丽风行(桑基图)

R绘图:相关性分析与作图(单基因相关性)

R绘图:相关性分析与作图R绘图

ggsci: 高大上的论文配色,一文解决配色问题

R绘图 ggpubr: 为学术而生

TCGA数据分析系列之火山图

R绘图 雷达图-单基因泛癌差异表达的另类展现形式

现实中有很多数据都是配对的,最常见的就是癌和癌旁,ggpubr包的ggpaired函数可以实现配对样本的统计和作图

加载数据

rm(list = ls())library(tidyverse)library(ggpubr)pairdata<-read.table('pair.txt',header = T,sep = '\t')

ggpaired用法

ggpaired(data, cond1, cond2, x = NULL, y = NULL, id = NULL, color = "black", fill = "white", palette = NULL, width = 0.5, point.size = 1.2, line.size = 0.5, line.color = "black", title = NULL, xlab = "Condition", ylab = "Value", facet.by = NULL, panel.labs = NULL, short.panel.labs = TRUE, label = NULL, font.label = list(size = 11, color = "black"), label.select = NULL, repel = FALSE, label.rectangle = FALSE, ggtheme = theme_pubr(), ...)

ggpaired函数有两种不同的方式做图,第一种是这样的

ggpaired(pairdata, cond1 = "condition1", cond2 = "condition2", fill = "condition", palette = "jco")

加上P值

ggpaired(pairdata, cond1 = "condition1", cond2 = "condition2", fill = "condition", palette = "jco")+ stat_compare_means(method = "t.test",paired = TRUE,label.y = 100)

那么如果是三组数据做配对分析呢?这个时候可以把数据转换成长数据,我们用tidyverse包中的gather函数来实现

drawdata<- pairdata %>% gather("condition", "value", -ID)

此时数据就变成了长数据

用第二种方式作图

ggpaired(drawdata, x = 'condition', y = 'value',id='ID', color = 'condition', palette = "jco", line.color = "gray", line.size = 0.4, short.panel.labs = FALSE)+ stat_compare_means(method = "anova", label.y = 100)

用样本两两之间的配对T检验

my_comparisons <- list( c("condition1", "condition2"), c("condition1", "condition3"), c("condition2", "condition3") )ggpaired(drawdata, x = 'condition', y = 'value',id='ID', color = 'condition', palette = "jco", line.color = "gray", line.size = 0.4, short.panel.labs = FALSE)+ stat_compare_means(aes(label = ..p.signif..), method = "t.test",paired = TRUE, comparisons = my_comparisons)

这样就大功告成了

公众号“生信小课堂”

TCGA数据分析大全

(0)

相关推荐