How to draw the boxplot with significant level?

前端 未结 2 955
迷失自我
迷失自我 2020-12-01 01:26

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

2条回答
  •  隐瞒了意图╮
    2020-12-01 01:57

    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)
    

    enter image description here

提交回复
热议问题