[R] map with inset

David Carlson dcarlson at tamu.edu
Wed Oct 16 20:12:26 CEST 2013


I've had difficulty getting subplot() to work with maps (the
TeachingDemos and Hmisc versions seem to be the same). This will
work, but there should be a better way. You have to print the
inset map first or you will get an error message.

require(maps)
require(mapdata)
Layout <- matrix(c(rep(2, 3), 1), 2, 2)
colSize <- c(2, 1.1)
rowSize <- c(2, 1)
layout(Layout, colSize, rowSize)

# Inset map is number 1
par(mar=c(4.5, 1, 1, 4))
map("worldHires", c("Canada", "USA"), xlim=c(-170, -50),
ylim=c(24, 90), proj="gilbert")
box()

# Main map is number 2
par(mar=c(4.1, 4.1, 4.1, 4.1))
map("worldHires", c("Canada", "USA"), xlim=c(-75, -52),
ylim=c(40, 55), col="gray90", fill=TRUE)
map.axes()
map('rivers', add=TRUE)
map.scale(-73, 54, relwidth=0.2, ratio=FALSE)
rect(-59.5, 46.5, -52,52)
text(-53,51.5,"A")
rect(-69, 43, -59.5,49.5)
text(-60, 49, "B") 

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Bert Gunter
Sent: Wednesday, October 16, 2013 11:54 AM
To: David Winsemius
Cc: r-help at r-project.org; markw
Subject: Re: [R] map with inset

... and if that doesn't do it, check out the CRAN "spatial" task
view, The
"maptools" package  or others might have what you need with a
friendlier
interface.

Cheers,
Bert


On Wed, Oct 16, 2013 at 9:39 AM, David Winsemius
<dwinsemius at comcast.net>wrote:

>
> On Oct 16, 2013, at 3:47 AM, markw wrote:
>
> > Hi,
> >
> > I am trying to put an inset of North America onto a
finer-scale map and
> > cannot seem to get the two maps on the same plot.
> >
> > the main map is:
> > map("worldHires", c("Canada", "USA"), xlim=c(-75, -52),
ylim=c(40, 55),
> > col="gray90", fill=TRUE)
> > map.axes()
> > map('rivers', add=TRUE)
> > map.scale(-73, 54, relwidth=0.2, ratio=FALSE)
> > rect(-59.5, 46.5, -52,52)
> > text(-53,51.5,"A")
> > rect(-69, 43, -59.5,49.5)
> > text(-60, 49, "B")
> >
> > and in the bottom right corner I want the following map
scaled so it
> doesn't
> > overlap with my main map:
> > map("worldHires", c("Canada", "USA"), xlim=c(-170, -50),
ylim=c(24, 90),
> > proj="gilbert")
> >
> > Any suggestions?
>
> Take a look at eitehr of TeachingDemos or Hmisc packages. I
think they
> both have a `subplot` function (although the functions are not
the same.)
>
> --
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> 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.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374

	[[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.



More information about the R-help mailing list