基因组数据绘图R语言训练

boxplot、barplot-summary

2019-06-02  本文已影响115人  Juan_NF
一如既往的碎碎念:

相处了三个月的小伙伴走了,留下我们,又是一顿唏嘘;
成年后的相识都是这样,一转身就是一辈子,几乎是不会再见了;
前段时间看过这样的一句话:好像一个不怕颗粒无收的少年,共勉;

boxplot概念

barplot-method1

#####这里加载了ggpubr,加载了ggplot2,以及我想用的stat_compare_means;
library(ggpubr)
data("ToothGrowth")
test1 <- ToothGrowth
head(test1)
#ggplot2
p1 <- ggplot(test1,aes(x = supp, y = len,color = supp )) + ylim(0,45)+
       geom_boxplot()
my_comparisons <- list(c('OJ','VC'))
p1
p1+stat_compare_means(comparisons = my_comparisons,method = 't.test')

参数功能说明

barplot-method2

####ToothGrowth是内置数据集
data("ToothGrowth")
df <- ToothGrowth
my_comparisons <- list(c('0.5','1'),c('0.5','2'),c('2','1'))
p <- ggboxplot(df, x = "dose", y = "len",
               add=c('median_iqr'),
               add.params = list(size=0.5),
               fill = "dose",
               bxp.errorbar = T)+
  stat_compare_means(comparisons = my_comparisons,label.y=c(35,45,50))
###通过ggpar可以对上面的结果p进行调整
ggpar(p,
      ylim=c(0,60),
      xlab='dose',
      ylab='len',
      legend = "right",
      legend.title = "Dose (mg)")

参数功能说明

barplot-part1 数据准备

library(ggplot2)
data("ToothGrowth")
test1 <- ToothGrowth
head(test1)
library(plyr)
tgc <- ddply(test1, .(supp, dose), summarize,
             mean = round(mean(len), 6),
             sd = round(sd(len), 6),
             se = round(sd(len)/sqrt(length(len)),6))
p_value<- ddply(test1,.(dose),summarize,
      p= round(t.test(len~supp)[[3]],4))

参数功能说明

ddply(.data, .variables, .fun = NULL, ..., .progress = "none",
  .inform = FALSE, .drop = TRUE, .parallel = FALSE, .paropts = NULL)

barplot-part2 绘图

p<- ggplot(tgc, aes(x=dose, y=mean, fill=supp)) + 
  geom_bar(position=position_dodge(), stat="identity") +
  geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
                width=.2,                   
                position=position_dodge(.4))+xlab('dose')+ylab('len')
p+ annotate("text", x = 0.5, y = 18, label = p_value$p[1]) +
  annotate("text", x = 1.0, y = 27, label = p_value$p[2]) +
  annotate("text", x = 2.0, y = 30, label = "ns")+
  geom_segment(aes(x=0.4, y=16, xend=0.6, yend=16))+
  geom_segment(aes(x=0.4, y=15, xend=0.4, yend=16))+
  geom_segment(aes(x=0.6, y=15, xend=0.6, yend=16))

参数功能说明

上一篇 下一篇

猜你喜欢

热点阅读