R绘图:配对样本差异表达作图ggpubr
R绘图往期回顾:
R绘图:gggibbous,基于ggplot2的Moon charts
R绘图:ggeconodist,基于ggplot2的另类箱图
现实中有很多数据都是配对的,最常见的就是癌和癌旁,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)
这样就大功告成了
公众号“生信小课堂”
赞 (0)