Hi All, Have the following code. The graph works well plotting the 15 transect for me however the legend shows a total of 22 transects. The original data has 22 transects numbered from 1 to 22. New data set got only 15. How can I get the legend to show only the transects plotted.
# Create Line Chart TAll <- read.csv("TAll Data.csv") # convert factor to numeric for convenience TAll$Tran <- as.numeric(TAll$Trans) nTrans <- max(TAll$Trans) # get the range for the x and y axis xrange <- range(TAll$Temp) yrange <- range(TAll$Depth) # set up the plot plot(xrange, yrange, ylim = rev(yrange), type="n", xlab="Temp (deg C)", ylab="Depth (m)" ) colors <- rainbow(nTrans) linetype <- c(1:nTrans) plotchar <- seq(1,1+nTrans,1) # add lines for (i in 1:nTrans) { tree <- subset(TAll, Trans==i) lines(tree$Temp, tree$Depth, type="b", lwd=1.5, lty=linetype[i], col=colors[i], pch=plotchar[i]) } # add a legend legend(xrange[-2], yrange[-2], 1:nTrans, cex=0.8, col=colors, pch=plotchar, lty=linetype, title="Transect") Thanks for the help, Tinus -- M.J. Sonnekus PhD Candidate (The Phytoplankton of the southern Agulhas Current Large Marine Ecosystem (ACLME)) Department of Botany South Campus Nelson Mandela Metropolitan University PO Box 77000 Port Elizabeth South Africa 6031 Cell: 082 080 9638 E-mail: tsonne...@gmail.com [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.