Reputation: 225
The axis labels for plot
s in R default to the center of their respective axis. I would like to move the axis labels to the ends of the axes so that the horizontal "x" label is at the far right and the vertical "y" label is at the far top. What are some recommended ways to do this? Can one use mtext
in a clever way?
Upvotes: 2
Views: 2573
Reputation: 93938
Using the title
function you can also use the adj
argument, and the text will be placed the same distance from the axis as titles are by default:
plot(0,ann=FALSE)
title(xlab="right",ylab="top",adj=1)
In fact, you can do this all from within the plot
call too:
plot(0,adj=1,xlab="right",ylab="top")
Be aware that this second example will also right align the main
title in the instance of something like:
plot(0,adj=1,xlab="right",ylab="top",main="yeah")
Upvotes: 2
Reputation: 121618
Using mtext
and playing with adj
parameter:
plot(0,ann=FALSE)
mtext('right',side=1,line=2,adj=1,col='red',cex=2)
mtext('top',side=2,line=2,adj=1,col='blue',cex=2)
Upvotes: 3