eddie
eddie

Reputation: 21

Axis label placement

I've got a probably fairly simple question. I want to put my y-axis label horizontally above the y-axis, in stead of the default (vertically alongside the y-axis). This probably requires a par() command, but which one?

thanks in advance!

Upvotes: 2

Views: 652

Answers (1)

eyjo
eyjo

Reputation: 1210

I don't think par is what you want. You could just adjust the default, exclude the label of the y-axis with ylab = "" and manually add your text with marginal text input (mtext). Example:

xx <- 1:20
yy <- 55 + 50 * xx - 3 * xx ^ 2

plot(x = xx, y = yy, type = "l", ylab="")
mtext("yy", side = 3, at = -1)

Or as a function:

newplot <- function(xx, yy) {
  plot(x = xx, y = yy, type = "l", ylab="")
  mtext(deparse(substitute(yy)), side = 3,
    at = - sum(range(xx)) / range(xx)[2])
}

Upvotes: 4

Related Questions