Rotating axis label in R
14,790
try adding las=2
axis(1, at=c(-2, -1, 1.9, 2), labels=c("8.07", "8.976", "11.7",
"11.9"), tck=.01, cex.axis=0.9, srt=45, col.ticks = "grey", las=2)
Author by
user81715
Updated on June 04, 2022Comments
-
user81715 almost 2 years
I would like help with rotating the axis label for the following plot. As is currently set up, the final label is not displayed because of limited space. I understand text, srt codes are used for this purpose but have not been able to rotate the labels that are currently shown (new numbers instead emerged IN the graph itself):
Xmin=0-2 Xmax=0+2 plot(x, y, type='n', xlab='x-axis', col.axis="grey", cex.axis=0.7, tck=-.02, xaxt="n") x <- c(-2,2) y <- c(-1,1) plot(x, y, type='n', xlab='x-axis', col.axis="grey", cex.axis=0.7, tck=-.02, xaxt="n") abline(a=-.6, b=-.2, lty=1, pch=15, lwd=1, col='black') abline(a=.03, b=.2, lty=5, pch=15, lwd=1, col='black') axis(1, at=c(-2, -1, 1.9, 2), labels=c("8.07", "8.976", "11.7", "11.9"), tck=.01, cex.axis=0.9, srt=45, col.ticks = "grey")
-
user81715 almost 8 yearsWorked beautifully! This is an entirely different question but the limited space between the last 2 points seems to require 1) increasing space 2) reducing font size or 3) perhaps another degree of rotation (45degrees?) Is there a most obvious solution to this issue?
-
greengrass62 almost 8 yearsMy first reaction is that rotation wouldn't seem to get you more white space IMO. You could maybe fudge something in with 'text(1,1,"hlp", srt=90)', but you'll need to tweak the 1's to get the placement to what you want.
-
user1424739 over 2 yearsDoes srt work in
axis()
? I don't see it works on my test. Sotext()
has to be used instead?