简体   繁体   中英

How to draw a boxplot whose staples looks like a square bracket in R

How to draw a box plot like this:

由R绘制的盒子图

make the staples, the mark of data within 1.5 IQR of the lower/upper quartile, looks like a square bracket.

I tried:

bx = sapply(5:1, function(x) rnorm(100, x, sqrt(x)))

boxplot(bx, col = "gray", pch = "", boxwex = 0.3,
  medlwd = rep(3, 4), medcol = rep("white", 4),
  outlty = 1, outwex = 1, 
  whisklty = 1, 
  staplelty = 1, staplewex = 1,
  names = paste0("mu = ", 5:1))

title(main = "n = 100")

在此输入图像描述


I do not believe it is possible to do this with staplelty . However, you can just draw the staple as a horizontal line and add the vertical ticks.

boxplot(iris[,1:4], outlty=1, pch="")

for(i in 1:4) {
    segments(c(i-0.2,i+0.2), BP$stats[5,i], c(i-0.2,i+0.2), BP$stats[5,i] - 0.1)
    segments(c(i-0.2,i+0.2), BP$stats[1,i], c(i-0.2,i+0.2), BP$stats[1,i] + 0.1)
}

Boxplot与花式钉书钉

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM