On Thu, 12 Feb 2009, Peter Jepsen wrote:

Dear all,

I have only just begun plotting on maps, so please bear with me. I am
plotting a map of Denmark in which each county is colorcoded by its
incidence of a particular disease. I am using the map data found at
http://biogeo.berkeley.edu/bgm/gdatares.php. The map is perfect, but the
island of Bornholm, which is located far east of the rest of Denmark, is
in its rightful place. To make the map look better, I want to move it
northwest and put a box around it - this is common practice for maps of
Denmark, in case you wonder.

It strikes me that you could use layout() in base graphics - not elegant, and needs care, but may provide a framework. The limitation is that you seem to have to operate in non-overlapping rectangles:

library(rgdal)
dnk <- readOGR(".", "DNK2")
ID_bornholm <- (1:248 %in% which(dnk$NAME_1 == "Bornholm"))
# find the relative width of Bornholm and the rest of Denmark, about 1/10
diff(t(bbox(dnk[!ID_bornholm,])))[1]
diff(t(bbox(dnk[ID_bornholm,])))[1]
ly <- layout(cbind(matrix(rep(1, 180), ncol=10), c(rep(0, 14), 2, 2, 0, 0)))
opar <- par(mar=c(1,1,1,0))
plot(dnk[!ID_bornholm,])
box()
par(mar=c(1,0,1,1))
plot(dnk[ID_bornholm,])
box()
layout(1)
par(opar)

The scale isn't quite correct, but could be improved by fine tuning. Just using an index and subsetting only at plotting lets you add attributes to the original data frame, and keeps things in the same place until they need to be separated. I think that this is more robust than shifting the coordinates, though you could use elide() methods in maptools to do:

library(maptools)
bornholm <- dnk[ID_bornholm,]
rdnk <- dnk[!ID_bornholm,]
bbox(rdnk)
bbox(bornholm)
ebornholm <- elide(bornholm, shift=c(-2.4, 2.4))
bbox(ebornholm)
summary(ebornholm)
proj4string(ebornholm) <- CRS(proj4string(rdnk))
summary(ebornholm)
ednk <- spRbind(rdnk, ebornholm)
plot(ednk, axes=TRUE)
# your choice of box, click on SW and NE corners
xy <- locator(2)
rect(xy$x[1], xy$y[1], xy$x[2], xy$y[2])

But the geographer in me worries about putting Bornholm on land in Sweden - if you run this object out with writeOGR and the KML driver and view in Google Earth, it is just south of Bollebygd.

Hope this helps,

Roger


I thought that I could simply find the coordinates for Bornholm and
change them by subtraction/addition, but I can't make it work.

For simplicity, I first create a separate dataset for Bornholm:

born <- dmk[dmk[[3]]=="Bornholm",]
class(born)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"

The output from the command -slot(born, "polygons")- is long and pasted
at the bottom of this mail. Bornholm is made up of 5 polygons. How do I
access and change the coordinates?

----
sessionInfo()
R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=
Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base


other attached packages:
[1] RColorBrewer_1.0-2 maptools_0.7-18    sp_0.9-29
foreign_0.8-30
[5] chron_2.3-28       reshape_0.8.2      plyr_0.1.4         epiR_0.9-14


loaded via a namespace (and not attached):
[1] grid_2.8.1      lattice_0.17-20
----
Thank you in advance for any help!

Kind regards,
Peter Jepsen, MD.


--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [email protected]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to