[R] plotting on map

Michael R. Head burner at suppressingfire.org
Tue Mar 3 00:34:37 CET 2009


On Mon, 2009-03-02 at 23:15 +0000, Dr. Alireza Zolfaghari wrote:
> Hi list,
> I want to plot state Texas using map function. I wrote the following code to
> plot the grid boundary for Texas:
> ################################
> library(maps)
>     require("mapproj")
>     longlatLimit<-c(-106.65,  -93.53 ,  25.93 ,  36.49)
>     par(plt=c(0,1,0,1),cex=1,cex.main=1)  #Set plotting parameters
>     map(projection="azequalarea",
> type="n",xlim=longlatLimit[1:2],ylim=longlatLimit[3:4])
>     bound<-c(floor(.map.range[1]), ceiling(.map.range[2]),
> floor(.map.range[3]), ceiling(.map.range[4]))
>     map.grid(lim=bound,col="light grey")
> ####################################
> Here is the problem I face:
> 1-I want the latitude boundary to be from 25 to 36 degree, but it goes from
> 25 to 32

How about this:


library(maps)
    require("mapproj")
    longlatLimit<-c(-106.65,  -93.53 ,  25.93 ,  36.49)
    par(plt=c(0,1,0,1),cex=1,cex.main=1)  #Set plotting parameters
    map(projection="azequalarea", type="n",xlim=longlatLimit[1:2],ylim=longlatLimit[3:4])
    bound<-c(floor(longlatLimit[1]), ceiling(longlatLimit[2]), floor(longlatLimit[3]), ceiling(longlatLimit[4]))
    map.grid(lim=bound,col="light grey")

> 2-When I copy the plot on pdf, the top of map will be shrinked
> I appreciate if some one come back to me with solution.

when I wrap the above in 
pdf("test.pdf")
...
dev.off()

I see the full PDF, though there is extra space on the page around it.

I frequently use pdf2ps to get the tight bounds on the graphic when I'm
including it in latex:
$ pdf2ps test.pdf - | grep "^%%BoundingBox:[0-9 ]*$" | cut -f 2- -d ' '
84 222 452 493

which can be used like so: 
\includegraphics[width=0.9\linewidth,viewport=84 222 452 493]{test}

> Regards,
> Alireza
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.
> 
-- 
Michael R. Head <burner at suppressingfire.org>
http://www.suppressingfire.org/~burner/
http://suppressingfire.livejournal.com


More information about the R-help mailing list