[R-sig-Geo] Scale bar in base plot

Tim Clark mudiver1200 at yahoo.com
Thu Oct 15 00:19:00 CEST 2009


Dear List,

I am trying to place a scal bar in a plot and can't find a function to do it with base graphics.  Is there one?  I have mfrow = c(3,3) and would like to place the scale bar in the last pannel. An example of what I am wanting follows.  

Thanks!

x <- 0:12
y <- sin(pi/5 * x)
op <- par(mfrow = c(3,3), mar = .1+ c(2,2,3,1))
for (tp in c("p","l","b",  "c","o","h",  "s","S")) {
   plot(y ~ x, type = tp,
        main = paste("plot(*, type = \"",tp,"\")",sep=""))
   if(tp == "S") {
      lines(x,y, type = "s", col = "red", lty = 2)
      mtext("lines(*, type = \"s\", ...)", col = "red", cex=.8)
   }
}

#Plot a scale bar in the bottom right pannel
plot.new()
legend("topleft",legend=c("Scale Bar"))

par(op)




Tim Clark
Department of Zoology 
University of Hawaii



More information about the R-sig-Geo mailing list