[R] text/mtext axis labels on graphs

Martin Hughes M.Hughes at bath.ac.uk
Thu Oct 7 12:29:49 CEST 2010


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




-- 
Martin Hughes
MPhil/PhD Research in Biology
Rm 1.07,  4south
University of Bath
Department of Biology and Biochemistry
Claverton
Bath    BA2 7AY
Tel: 01225 385 437
M.Hughes at bath.ac.uk
http://www.bath.ac.uk/bio-sci/biodiversity-lab/hughes.html



More information about the R-help mailing list