R:如何在箱线图中共享标签名称?

Xi'*_*'an 2 label r boxplot

我做了下图 在此处输入图片说明

用命令

boxplot(tstats,names=c(expression(bar(x)),"","med(x)","","mad(x)","",
         var(x)","",expression(q[.75]-q[.25]),""),
         col=rep(c("wheat","chocolate"),5))
abline(h=2,col="steelblue",lty=2)
abline(h=-2,col="steelblue",lty=2)
title(main="normal data")
Run Code Online (Sandbox Code Playgroud)

但我想将两个(小麦和巧克力)盒子之间的共享名称居中。如何修改第一个轴标签?

csg*_*pie 5

像这样的事情应该做你想做的:

##Some dummy data
dd = data.frame(values = rnorm(40), type=LETTERS[1:4])

##Don't plot the axes labels
##but add in the "plot frame"
boxplot(dd$values ~ dd$type, axes=FALSE, 
                  frame.plot=TRUE, ylim=c(-4, 4))

##Now add in the y-axis
axis(2, seq(-4,4,by=2))
##Add in the x-axis at points: 1.5 and 3.5
axis(1, c(1.5,3.5), c("Med", "Mad"))
Run Code Online (Sandbox Code Playgroud)