简体   繁体   中英

R plot: adding a title to the y-axis

I would like to add a title for the y-axis of the top plot. Of course, in the toy example below, I can use the ylab argument. But I am looking for another option to fit with my actual problem. It appears that mtext() does not do the job in this case. Any other idea?

x11()
par(mfrow=c(2, 1))
plot(1:10, ylab = " ")
mtext(text = "y-label", side = 2, line = -2, outer = TRUE)
plot(1:10, ylab = " ")

在此处输入图片说明

mtext(text = "y-label", side = 2,line=2, at=26, outer = FALSE)

You will have to play around where at= is to find the sweet spot for both graphs but this will do what you are asking. 6 seems to be a good number for the bottom graph if anything. (Using the example)

If you imagine line to be an x co-ordinate and at to be ay co-ordinate then you can just play around until you find what fits.

Probably not as clean and cut as you wanted but it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM