boxplot、barplot-summary

作者: Juan_NF | 来源:发表于2019-06-02 15:45 被阅读115次
一如既往的碎碎念:

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

boxplot概念

  • 利用数据中的五个统计量:最小值(Q1-1.5(IQR))、第一四分位数( Q1)、中位数(Q2)、第三四分位数(Q3)与最大值(Q3+1.5(IQR))来描述数据的一种方法。


  • IQR即Q3-Q1;

  • 超出maximum(inner fence)和minimum(outer fence)的即outlier;

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')

参数功能说明

  • comparison设置比较的对象,需要用list格式;
  • stat_compare_means可以设置检验的方式;


    method1

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)")

参数功能说明

  • 依据自己的需要,选择add中的mean_se、median_iqr等;
  • bxp.errorbar(T/F)设置是否展示箱线图的误差线;
  • 通过ggpar可以对ggboxplot的结果进行调整;


    method2

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)
  • ddply(依据.variables)对数据框进行分组,将.fun作用于各个分组,并返回作用结果;
  • summarize是一个对结果总结的函数,可返回一个数据框的结果;
  • errorbar可采用sd(标准差)、se(标准误/标准误差)、置信区间的计算结果;

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))

参数功能说明

相关文章

  • boxplot、barplot-summary

    一如既往的碎碎念:相处了三个月的小伙伴走了,留下我们,又是一顿唏嘘;成年后的相识都是这样,一转身就是一辈子,几乎是...

  • Python可视化17seborn-箱图boxplot

    本文系统详解利用python中seaborn.boxplot绘制箱图boxplot。seaborn.boxplot...

  • 2020-06-29

    R语言boxplot绘图函数 boxplot 用于绘制箱线图,我们都知道boxplot 用于展示一组数据的总体分布...

  • boxplot

    https://biit.cs.ut.ee/clustvis/ https://discuss.analytics...

  • boxplot

  • boxplot

    library(ggplot2) library(magrittr) library(ggpubr) a=read...

  • Boxplot

    1.最简单boxplot 2.自定义颜色的boxplots

  • R第十二天

    数据可视化 一、箱线图 boxplot(数据集的变量)——col调颜色 变量~变量 boxplot.stats()...

  • 2021-04-01boxplot怎么看?是什么意思?

    定义 按给定数值做箱线图。 格式 boxplot(x, ...)S3方法对对象'formula' boxplot(...

  • R包: RColorBrewer的使用

    比较适合画boxplot参考:

网友评论

    本文标题:boxplot、barplot-summary

    本文链接:https://www.haomeiwen.com/subject/lvhhtctx.html