Skip to content

text/mtext axis labels on graphs

3 messages · Martin Hughes, Jim Lemon, Greg Snow

#
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

Thanks
Martin
#
On 10/07/2010 09:29 PM, Martin Hughes wrote:
Hi Martin,
Have a look at the staxlab function in the plotrix package, particularly 
the "srt" argument.

Jim
#
For your specific question, Jim's answer of staxlab is the best, but for general placing of text or other graphics elements relative to figure, plot, or device look at the grconvertX and grconvertY functions.