如何对齐不同高度的轴标签?

How to align axis labels of different height?

不同高度的(x轴)标签如何水平对齐? 这是一个例子:

nms <- c(expression(A), expression(B), expression(C),
         expression(D[1]), expression(E^1), expression(F))
boxplot(count ~ spray, data=InsectSprays, names=nms)

标签 "E" 与 A、B、C 和 F 很好地对齐,但是 D_1 不是。 D_1 如何与其他标签对齐?

例如,您可以使用 mtext 手动绘制轴。

## reset defalt names 
boxplot(count ~ spray, data=InsectSprays,names=NA)
## adjustemnt vectors , see that only d_1 has an adj !=0
adj=c(0,0,0,0.2,0,0)
## loop over expressions and plot them one by one
for(s in seq_along(nms))
  mtext(nms[s], side=1, line=1,at=s,padj=adj[s])