---------- Forwarded message ----------
From: Margaret Donald <[hidden email]> Date: 5 May 2016 at 17:52 Subject: Contour colour gradations and overplotting problems To: [hidden email] Dear List, I have used the package nlme to interpolate a set of values which I then want to show as a contour graph. # Plot the image: First method: #------------------------------------- zmesh <- matrix(zmesh,ng,ng) image(xgrid,ygrid,zmesh,bty="l",xlab="Easting",ylab="Northing", col=terrain.colors(1000), xlim=c(xmin, xmax), ylim=c(ymin, ymax), main="Bivariate smooth of number of native species/.01 ha") points(x,y,col="red",cex=0.7) lines(Jboundary[,1],Jboundary[,2],col="blue",lwd=2) This method overplots the points and lines correctly, but I don't get a scale bar. # Plot the image: Second method: #------------------------------------- filled.contour(xgrid,ygrid,zmesh,col=terrain.colors(25), xlab="Easting",ylab="Northing", xlim=c(xmin, xmax), ylim=c(ymin, ymax)) title ("Number of native species/.01 ha") points(x,y,col="red",cex=0.7) lines(Jboundary[,1],Jboundary[,2],col="blue",lwd=2) This method overplots the points and lines incorrectly. I DO get a scale bar. However, I would like to reverse the colour scale so that dark green represents my highest values and the burnt-out pale pink represents the lowest value. (I would like this because the high values represent well treed areas and the low values often represent cleared ground...) I am hoping someone knows a set of functions which graph my coloured contour plot correctly, with the desired colours and which correctly overplots the lines and points on the scale of the contour plot. Regards, Margaret Donald -- Margaret Donald BA (Hon), M. App Stat, Ph.D, AStat Statistician, Anne Clements & Associates -- Margaret Donald BA (Hon), M. App Stat, Ph.D, AStat Statistician, Anne Clements & Associates [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology |
One option, if you are satisfied with the results of plotting, is to draw
your own scale bar. Drawing a scale bar from scratch requires only minimal code. The approach below places the scale bar relative to percentages of the width and height of the plot area, so is readily adapted to plots with different x and y limits. #A plot plot(log(1:100), 1:100, pch=21, bg=topo.colors(100)) #Add to plot on the current device par(new=TRUE) #Set up coordinate system. This one #is easy to visualize, e.g., x=0.2 is #approximately 20% of the distance #from left to right, y=0.20 is approx. #20% of the distance from bottom to #top. plot.window(xlim=c(0,1), ylim=c(0,1)) #Larger value gives smoother gradation #of colors on scale n <- 100 #On the x axis, the scale will run from #0.05 t0 0.055, left to right. Width is #approximately 5% of width of plotting #region. x1 <- rep(0.05,100) x2 <- x1+0.05 #On the y axis, the scale will run from #20% of the way up to 80% of the way up. y1 <- seq(from=0.2, to=0.8, length.out=100) y2 <- y1+0.01 #Draw colored rectangles and frame the entire #collection. I used topo.colors() for simplicity, #but any vector of 100 color specifications would #work. For fine control, see functions for color ramps. rect(x1,y1,x2,y2, border=NA, col=topo.colors(100)) rect(x1[1],y1[1],x2[n],y2[n]) #Adding text n.labels <- 4 x <- unique(x2) y <- seq(min(y1), max(y2), length.out=n.labels) text(x, y, c("Label 1", "Label 2", "Label 3", "Label 4"), adj=-0.2) On Thu, May 5, 2016 at 5:07 AM, Margaret Donald <[hidden email] > wrote: > ---------- Forwarded message ---------- > From: Margaret Donald <[hidden email]> > Date: 5 May 2016 at 17:52 > Subject: Contour colour gradations and overplotting problems > To: [hidden email] > > > Dear List, > > I have used the package nlme to interpolate a set of values which I then > want to show as a contour graph. > > # Plot the image: First method: > #------------------------------------- > zmesh <- matrix(zmesh,ng,ng) > image(xgrid,ygrid,zmesh,bty="l",xlab="Easting",ylab="Northing", > col=terrain.colors(1000), xlim=c(xmin, xmax), ylim=c(ymin, ymax), > main="Bivariate smooth of number of native species/.01 ha") > points(x,y,col="red",cex=0.7) > lines(Jboundary[,1],Jboundary[,2],col="blue",lwd=2) > > This method overplots the points and lines correctly, but I don't get a > scale bar. > > > > # Plot the image: Second method: > #------------------------------------- > filled.contour(xgrid,ygrid,zmesh,col=terrain.colors(25), > xlab="Easting",ylab="Northing", > xlim=c(xmin, xmax), ylim=c(ymin, ymax)) > title ("Number of native species/.01 ha") > points(x,y,col="red",cex=0.7) > lines(Jboundary[,1],Jboundary[,2],col="blue",lwd=2) > > This method overplots the points and lines incorrectly. I DO get a scale > bar. > > However, I would like to reverse the colour scale so that dark green > represents my highest values and the burnt-out pale pink represents the > lowest value. (I would like this because the high values represent well > treed areas and the low values often represent cleared ground...) > > I am hoping someone knows a set of functions which graph my coloured > contour plot correctly, with the desired colours and which correctly > overplots the lines and points on the scale of the contour plot. > > > Regards, > > Margaret Donald > > -- > Margaret Donald BA (Hon), M. App Stat, Ph.D, AStat > Statistician, Anne Clements & Associates > > > > -- > Margaret Donald BA (Hon), M. App Stat, Ph.D, AStat > Statistician, Anne Clements & Associates > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-ecology mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > -- Glen Sargeant, Ph.D. Research Wildlife Biologist/Statistician USGS Northern Prairie Wildlife Research Center E-mail: [hidden email] Phone: (701) 253-5528 [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Glen Sargeant
Research Wildlife Biologist |
Free forum by Nabble | Edit this page |