r-我如何绘制一个有固定宽度和正确标签的方框图



我写了这段代码,但我不能固定方框部分的宽度,最近标签垂直显示!但昨天它的工作是正确的!!!

dt=rnorm(100)
l=c("min:","1st Qu:","median:","3rd Qu:","max:")
bxp <- boxplot(dt, axes=TRUE,col = '#fb9a99')
v=round(bxp$stats,2)
mtext(paste(l,v),side = 4, at=bxp$stats[c(1,2,3,4,5)], line=-5.5)

为了再现性,请使用set.seed()函数。

# set seed
set.seed(1980)
# your data and text
dt <- rnorm(100)
l <- c("min:", "1st Qu:", "median:", "3rd Qu:", "max:")
# your boxplot
# with boxwex parameter you control the width of the boxes
bxp <- boxplot(dt, 
               axes = TRUE, 
               col = '#fb9a99', 
               boxwex = 0.5)
v <- round(bxp$stats, 2)
# your text
# with las parameter you control orientation of the text
mtext(paste(l, v), 
      side = 4, 
      at = bxp$stats[c(1, 2, 3, 4, 5)], 
      line = -10.5, 
      las = 1)

最新更新