[R] equivalent of Splus command axis(..., srt=45, adj=1) in R
Marc Schwartz
MSchwartz at medanalytics.com
Sat Aug 16 23:39:26 CEST 2003
On Sat, 2003-08-16 at 12:45, Marco Bianchi wrote:
> Dear R-users
> moving from Splus to R (under Windows), I notice that command "srt" within a
> plot in the original Splus code is ignored by R.
> For example, if a plot something and then include the line of code
>
> axis(1, at=Time, labels=Text, srt=45, adj=1)
>
> the srt=45 command within the axis() command fails to draw Text at 45
> degrees on the x-axis in R but it works properly in Splus.
> I will go through the relevant documentation in the R manuals but if anyone
> has already had this problem and/or knows the corresponding command of
> srt=45 in R, please let me know.
>
> Kind regards
> Marco Bianchi
In R, the axis command does not accept or utilize par("srt"), thus
passing it as an argument has no effect.
A trick, based upon an initial post from Uwe Ligges some time back was
reflected in a post that I had this past May:
http://maths.newcastle.edu.au/~rking/R/help/03a/5153.html
The relevant example code is:
# First draw the plot without axes
plot(1:10, xlab = "My label", axes = FALSE)
# Now plot the x axis, but without labels
axis(1, at=seq(1, 10, by=2), labels = FALSE)
# Now draw the textual axis labels
text(seq(1, 10, by = 2), par("usr")[3] - 0.2,
labels = c("first", "second", "third", "fourth", "fifth"),
srt = 45, pos = 1, xpd = TRUE)
By using text(), which is normally used to put text within the plot
region, you can utilize par("srt"). However, you also need to combine
this with par("xpd") so that the text will not be clipped at the plot
region, thus not show.
By adjusting the negative offset of 'par("usr")[3] - 0.2', you can
move the labels vertically to account for the length of the text
components. A larger value moves the text down further below
par("usr")[3], which is the value of y at the intersection of the
x-axis.
HTH,
Marc Schwartz
More information about the R-help
mailing list