如何绘制具有显着水平的箱线图? [英] How to draw the boxplot with significant level?

查看:24
本文介绍了如何绘制具有显着水平的箱线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间我问了一个关于绘制箱线图的问题Link1.

Some time ago I asked a question about drawing boxplot Link1.

我有一些包含 3 个不同组(或标签)的数据请在此处下载.我可以使用以下 R 代码来获取箱线图

I have got some data with 3 different groups (or labels) Please down load here. I can use the following R codes to get the boxplot

library(reshape2)
library(ggplot2)

morphData <- read.table(".\TestData3.csv", sep=",", header=TRUE);
morphData.reshaped <- melt(morphData, id.var = "Label")

ggplot(data = morphData.reshaped, aes(x=variable, y=value)) + 
  + geom_boxplot(aes(fill=Label))

在这里,我只是想知道如何将显着性水平置于箱线图之上.为了清楚起见,我在此处放了一张从论文中截取的屏幕截图:

Here I just wondering how to put the significant level above the boxplot. To make myself clear I put a screenshot cut from a paper here:

推荐答案

我不太明白具有显着水平的箱线图是什么意思,但这里有一个建议如何生成这些条:我将使用条形坐标解决这个构造小数据框的问题.举个例子:

I don't quite understand what you mean by boxplot with significant level but here a suggestion how you can generate those bars: I would solve this constructing small dataframes with the coordinates of the bars. Here an example:

pp <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
df1 <- data.frame(a = c(1, 1:3,3), b = c(39, 40, 40, 40, 39))
df2 <- data.frame(a = c(1, 1,2, 2), b = c(35, 36, 36, 35))
df3 <- data.frame(a = c(2, 2, 3, 3), b = c(24, 25, 25, 24))

pp + geom_line(data = df1, aes(x = a, y = b)) + annotate("text", x = 2, y = 42, label = "*", size = 8) +
     geom_line(data = df2, aes(x = a, y = b)) + annotate("text", x = 1.5, y = 38, label = "**", size = 8) +
     geom_line(data = df3, aes(x = a, y = b)) + annotate("text", x = 2.5, y = 27, label = "n.s.", size = 8)

这篇关于如何绘制具有显着水平的箱线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆