Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

r - How to draw the boxplot with significant level?

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

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:

Boxplot

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I know that this is an old question and the answer by DatamineR already provides one solution for the problem. But I recently created a ggplot-extension that simplifies the whole process of adding significance bars: ggsignif

Instead of tediously adding the geom_line and annotate to your plot you just add a single layer geom_signif:

library(ggplot2)
library(ggsignif)

ggplot(iris, aes(x=Species, y=Sepal.Length)) + 
  geom_boxplot() +
  geom_signif(comparisons = list(c("versicolor", "virginica")), 
              map_signif_level=TRUE)

Boxplot with significance bar

Full documentation of the package is available at CRAN.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...