[R] Graph Script/X-axis label Problem
jimdare
jamesdare26 at gmail.com
Fri Jan 9 02:18:03 CET 2009
Hi, I created the script below to plot multiple graphs. It seems to work
pretty well (see BYX7) except when the max value for catch or TACC is very
small. In this case the x-axis labels are removed from the x-axis (see
BYX10). I can't figure out why given that y co-ordinate for the text
function is par("usr")[1] - 0. Shouldn't this mean that it is flush to the
x-axis? Can anyone see what is going wrong?
SCRIPT:
fish<-read.csv(file="C:/Documents and Settings/darej/My
Documents/James/R/fishmany.csv",sep=",",head=T)
x.sp <- split(fish, list(fish$Species, fish$Stock))
for (i in x.sp){
par(mar = c(7, 6, 4, 2) + 0.1)
yaxmax=(max(i$TACC, i$Catch))*1.2
mp <- barplot(i$TACC, xaxt="n",
main=paste(i$Stock[1]),space=0,xlab="",ylab="",ylim=c(0,max(i$TACC,
i$Catch))*1.2)
axis(1, labels = FALSE)
labels <- paste(i$Year, sep = " ")
text(mp, par("usr")[1] - 0, srt = 45, cex=0.75,adj = 1,
labels = labels, xpd = TRUE)
lines(mp, i$Catch, type='o', pch=18,lwd=2)
legend("topright",legend=
c("TACC","Catch"),bty="n",col=c("black","black"),lty=c(0,1),lwd=c(0,2),
pch=c(22,18),pt.bg=c("grey",NA),pt.cex=2)
xmax=length(i$Year)
text(xmax*0.6, par("usr")[1] - (0.1*yaxmax), srt = 0, adj = 1,
labels = "Fishing Year", xpd = TRUE,cex=1.2)
text(xmax*-0.15, par("usr")[1] + (0.6*yaxmax), srt = 90, adj = 1,
labels = "Tonnes", xpd = TRUE,cex=1.2)
savePlot(filename=paste(i$Stock[1]),type="wmf")
}
http://www.nabble.com/file/p21364546/BYX7.gif
http://www.nabble.com/file/p21364546/BYX10.gif
--
View this message in context: http://www.nabble.com/Graph-Script-X-axis-label-Problem-tp21364546p21364546.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list