[R-sig-eco] Fixing vertical and horizontal axes in R

Shane Baylis shane.m.baylis at gmail.com
Thu May 12 08:51:26 CEST 2016


Hi Margaret,

eqscplot() can handle this scenario. Can you try:

fn <- "SpeciesRateLevels11F.jpg"
jpeg(fn, width = 600, height = 700)
zmeshR <- matrix(zmeshR,ng,ng)
eqscplot(x = x, y = y, type = "n", xlab = "Easting", ylab = "Northing",
               main = "Estimated number of native species / .01 ha")
image(xgrid,ygrid,zmeshR,bty="l",
       col=zz.colors,
       add = TRUE)
points(x,y,col="red",cex=0.7)
lines(Jboundary[,1],Jboundary[,2],col="black",lwd=2)

b <- contourLines(xgrid,ygrid ,
              zmeshR, nlevels=11,
              levels = c(2, 4, 6, 8,10,12,14,16,18,20,22))
for (i in 1:11){
     lines(b[[i]], col="black", lwd=1)
}

In this case the limits of the plot will be set in terms of x and/or y, 
rather than xgrid and ygrid. If you need to include more of the 
background that was generated in your original image() call, you can use 
dummy x and y variables in the eqscplot() call, so that the whole 
image() area falls between their minimum and maximum.

Cheers,

  Shane



On 12/05/16 15:55, Margaret Donald wrote:
> Thanks, Shane, but that is precisely my problem. The final graph will 
> not be the default windows size and I want to
>     a) nominate the overall height & width, and
>     b) enforce the equal scales on the x and y axes.
>
> My code currently looks like this:
>
> # Generate image plot 2:
> #-----------------------
> fn <- "SpeciesRateLevels11F.jpg"
> jpeg(fn, width=600, height=700)
> zmeshR <- matrix(zmeshR,ng,ng)
> image(xgrid,ygrid,zmeshR,bty="l",xlab="Easting",ylab="Northing",
>       col=zz.colors,  xlim=c(xx1, xx2), ylim=c(yy1, yy2),
>       main="Estimated number of native species /.01 ha")
> points(x,y,col="red",cex=0.7)
> lines(Jboundary[,1],Jboundary[,2],col="black",lwd=2)
>
> b <- contourLines(xgrid,ygrid ,
>              zmeshR, nlevels=11,
>              levels = c(2, 4, 6, 8,10,12,14,16,18,20,22))
> for (i in 1:11){
>     lines(b[[i]], col="black", lwd=1)
> }
>
> Cheers,
> Margaret Donald
>
>
> On 12 May 2016 at 14:02, Shane Baylis <shane.m.baylis at gmail.com 
> <mailto:shane.m.baylis at gmail.com>> wrote:
>
>     Hi Margaret,
>
>     It sounds like you're after eqscplot(), in package MASS. The
>     overall size can be set as for any plot window, but note that if
>     you scale the plot by dragging the limits of the plot window (or
>     similar), the plot will need to be re-generated after scaling the
>     window to ensure that equal-scale is maintained.
>
>     https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/eqscplot.html
>
>     Hope that helps,
>
>      Shane Baylis
>
>     On 12/05/16 13:13, Margaret Donald wrote:
>
>         I have a figure which uses the same measurement units both
>         vertically and
>         horizontally. I need the interval representing 20 m to be
>         identical for
>         both the x and y axes.  How do I specify this? And at the same
>         time dictate
>         the size of the overall graph which is being saved as a jpeg.
>
>
>         Regards,
>         Margaret Donald
>
>
>
>
>     _______________________________________________
>     R-sig-ecology mailing list
>     R-sig-ecology at r-project.org <mailto:R-sig-ecology at r-project.org>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>
>
>
> -- 
> Margaret Donald BA (Hon), M. App Stat, Ph.D, AStat
> Statistician, Anne Clements & Associates


	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list