[R] inset one map on top of another map

Ray Brownrigg Ray.Brownrigg at ecs.vuw.ac.nz
Wed Sep 28 02:26:34 CEST 2011


On Wed, 28 Sep 2011, Jean V Adams wrote:
> I want to overlay a small inset map on top of another map, but I can't
> figure out how to do it.
> For example, here are two different maps:
> 
> # map 1 - Ohio
> map("state", region= "ohio")
> 
> # map 2 - US with Ohio darkened
> map("state")
> map("state", region="ohio", fill=T, add=T)
> 
> I would like to add map 2 as a small inset in the corner of map 1.
> I have tried:
> 
> map("state", region= "ohio")
> par(new=TRUE, mar=c(3, 3, 15, 15))
> map("state")
> map("state", region="ohio", fill=T, add=T)
> 
> but this seems to erase map 1 and replace it with a full size version of
> map 2.
> 
> I can successfully overlay an unrelated plot using similar code:
> 
> map("state", region= "ohio")
> par(new=TRUE, mar=c(3, 3, 15, 15))
> plot(1:10, 1:10)
> 
> So, there must be something about the maps() function that I'm tripping
> over.

I think the problem is that map() 'insists' (in some sense) on a clean frame so it can get 
the aspect ratio right.

> 
> Any suggestions?
> 
How about something like:
map("state", region= "ohio", xlim=c(-85, -80), ylim=c(38, 42))
par(usr=c(-216, -66, 24, 144))		# you should be able to 'automate' this calculation
map("state", add=T)
map("state", region="ohio", fill=T, add=T)

HTH
Ray Brownrigg

> I am using R for Windows 2.13.0
> and the maps package version 2.1-5.
> 
> Jean
> 
> 
> `�.,,  ><(((�>   `�.,,  ><(((�>   `�.,,  ><(((�>
> 
> Jean V. Adams
> Statistician
> U.S. Geological Survey
> Great Lakes Science Center
> 223 East Steinfest Road
> Antigo, WI 54409  USA



More information about the R-help mailing list