Initial alignment of axis labels

It can be easily solved, but I didn’t find anything with Google, maybe because it’s hard to put into words. When running the following code

Dat<-matrix(c(1:10, 1:10, seq(0.1, 1, 0.1)), 10, 3)
par(mfrow=c(1, 2))
plot(Dat[,1], Dat[,2], ylab="Y", xlab=expression(paste("A unit (", m^2, ")", sep="")))
plot(Dat[,1], Dat[,3], ylab="Y", xlab="A unit")

I get a good plot, but the x-axis labels are not on the same baseline. The reason is that the label on the left graph has parentheses that reach the baseline of the text, and R overlays the labels so that the bottom of the text line is taken as the baseline when used expression()in the xlab command. Therefore, “Unit” is printed lower on the right graph than on the left figure (see Example of the image indicated by the red line). This is annoying if some labels have parentheses or letters with parts that reach the baseline (for example, "g", "q", etc.), while others do not. Is there any way to fix this?

enter image description here

+4
source share
1 answer

, , , , . "qqq" "ooo", , -, . , plotmath .

Plotmath (La) Tex, , , "". , , par mtext. , , , , , phantom . , :

plot(Dat[,1], Dat[,3], ylab="Y", 
  xlab=expression(paste(phantom('('),"A unit",phantom(')'))))

phantom parentheses

+4
source

All Articles