Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align axis labels of different height?

Tags:

r

axis

How can (x axis) labels of different heights be horizontally aligned? Here is an example:

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

The label "E" is nicely aligned with A,B,C and F, but D_1 isn't. How can D_1 be aligned with the other labels as well?

enter image description here

like image 218
Marius Hofert Avatar asked Oct 19 '22 02:10

Marius Hofert


1 Answers

You can plot manually the axis using mtext for example.

## 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])

enter image description here

like image 73
agstudy Avatar answered Oct 21 '22 17:10

agstudy