[R] text/mtext axis labels on graphs
Jim Lemon
jim at bitwrit.com.au
Thu Oct 7 13:27:59 CEST 2010
On 10/07/2010 09:29 PM, Martin Hughes wrote:
>
> Hello everyone
>
> I have problem with axis labels on graphs, I have my code as below:
>
> plot(0,0,xlim=c(1,ncol(PA)),ylim=c(1,nrow(PA)),main="Stratigraphic
> Range",xlab="Time
> Bins",ylab="Taxa",cex.axis=1.5,cex.lab=2,cex.main=2.5,mgp=c(5,1.5,0),xaxt="n")
>
>
> text(1:(length(strat_name)), y= 0, adj=1,
> srt=45,labels=strat_name,xpd=TRUE, cex=1) #adds text to x axis giving
> the strat names
> abline(v=(1:ncol(PA))+.5,col="grey",lty=3)
>
> cl <- rep(1,nrow(PA))
> cl[DistM$kill] <- 2
> for (i in 1:nrow(PA)) segments(min(which(PA[i,]==1))-.5,i,
> max(which(PA[i,]==1))+.5,i,lwd=3,col=cl[i])
>
>
> My problem lies with the x axis tick labels, I want my own labels added
> in so removed the one the plot function adds in normally.
>
> I use the text function as it allows me to fit my own text tick labels
> at an angle, HOWEVER the text function is VERY sensitive to the Y axis,
> I have multiple graphs on a page, each with a different y axis, so the
> labels move up and down depending on the scale of the Y.
>
>
> I tried using mtext which lets you put the text a certain distance from
> the x margin line, HOWEVER this function does not let you tilt the text
> to be an an angle
>
>
> Can anyone tell me of a way I can have both - ie text that is a
> specified distance from the margin AND tilted at and angle
>
Hi Martin,
Have a look at the staxlab function in the plotrix package, particularly
the "srt" argument.
Jim
More information about the R-help
mailing list