lukeg
lukeg

Reputation: 1357

repositioning of y-label in R

So taking the following dataset for example

attach(mtcars)
plot(wt,mpg, main="Scatterplot of wt vs. mpg")

Now using the mgp we can rescale the axis title, axis labels and axis line. Help can be found in ?par() I wish to move the position of the y label closer to the vertical label and keep the x at the default value of 3. How can one do such?

Something along the lines of mgp = c((1.5,3),1,0)

Upvotes: 0

Views: 83

Answers (2)

csgillespie
csgillespie

Reputation: 60522

Another possibility is to use mtext to add the labels after plotting. So something like:

plot(wt,mpg, main="Scatterplot of wt vs. mpg", xlab="", ylab="")
mtext("X", side=1, padj=2)
mtext("Y", side=2, padj=-3)

Upvotes: 1

Ruthger Righart
Ruthger Righart

Reputation: 4921

The following would do it, you need to play around with the three parameters:

par(mgp=c(axis.title.position=2, axis.label.position=1, axis.line.position=0))
plot(wt,mpg, main="Scatterplot of wt vs. mpg")

Upvotes: 1

Related Questions