How to adjust the size of y axis labels only in R?

后端 未结 3 1447
一个人的身影
一个人的身影 2021-02-03 18:19

How can I adjust only the size of Y-axis labels in R?

I know that cex.axis alters the size of the axis labels but it only affects the x-axis. Why, and how can I adjust t

3条回答
  •  旧巷少年郎
    2021-02-03 18:50

    As the title suggests that we want to adjust the size of the labels and not the tick marks I figured that I actually might add something to the question, you need to use the mtext() if you want to specify one of the label sizes, or you can just use par(cex.lab=2) as a simple alternative. Here's a more advanced mtext() example:

    set.seed(123)
    foo <- data.frame(X = rnorm(10), Y = rnorm(10))
    plot(Y ~ X, data=foo,
         yaxt="n", ylab="", 
         xlab="Regular boring x", 
         pch=16,
         col="darkblue")
    axis(2,cex.axis=1.2)
    mtext("Awesome Y variable", side=2, line=2.2, cex=2)
    

    enter image description here

    You may need to adjust the line= option to get the optimal positioning of the text but apart from that it's really easy to use.

提交回复
热议问题