[R-sig-Geo] World Map with Inset Map
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Wed Jun 13 23:38:31 CEST 2012
Hi,
maybe I've overlooked something obvious but I'm trying to generate _one_ plot of a world map (actually projected) with an inset of a specific zoomed area based on SpatialDataFrames.
I followed this example which makes usage of the library "maps":
http://wiki.cbr.washington.edu/qerm/sites/qerm/images/7/78/MakingAnInsetMapShorter.r
Thus I wrote this (as a minimal and naïve example):
library(maptools)
data(wrld_simpl)
# plot world map
plot(wrld_simpl, col = "khaki", bg = "azure2")
# define inset map location and size
par(plt = c(0.57, 0.87, 0.4, 0.7), new = TRUE)
# init inset map view port
plot.window(xlim = c(130, 180), ylim = c(40, 70))
# draw background
rect(130, 40, 180, 70, col = "azure2")
# plot zoomed inset map
plot(wrld_simpl, xlim = c(130, 180), ylim = c(40, 70),
col = "khaki", bg = "azure2", add = TRUE)
The problem is that the inset map won't be cropped, i.e. you see both maps overlapped.
What I'm doing wrong? Or is this with SpatialDataFrames not possible?
I'd be appreciated for any hint!
Kind regards,
--Hans
PS = sessionInfo():
R version 2.14.2 (2012-02-29)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] maptools_0.8-14 lattice_0.20-0 sp_0.9-96 foreign_0.8-49
loaded via a namespace (and not attached):
[1] grid_2.14.2 tools_2.14.2
More information about the R-sig-Geo
mailing list