How to put values on a boxplot for median, 1st quartile and last quartile?

后端 未结 4 1169
猫巷女王i
猫巷女王i 2020-12-10 16:29

How to put values on boxplot and control its width?

X<-c(1,2,,3,4,4,5,5,6,6,6,6,6,7)

I need to write values for min, max, 1st quartile,

4条回答
  •  庸人自扰
    2020-12-10 17:14

    You can use horizontal = TRUE get a horizontal boxplot and axes = FALSE to remove the axes. staplewex = 1 sets the staple width the same as the box width

    Then you can use fivenum to return the statistics used to create the boxplot and use these as text labels, fiddling with the y value until you have what you want

    boxplot(X, horizontal = TRUE, axes = FALSE, staplewex = 1)
    text(x=fivenum(X), labels =fivenum(X), y=1.25)
    

    enter image description here

    Note that i've inserted a 3 for the value missing in your example data X

提交回复
热议问题