[prev in list] [next in list] [prev in thread] [next in thread]
List: r-sig-geo
Subject: Re: [R-sig-Geo] adding a background shape to ssplot
From: "Hengl, T." <T.Hengl () uva ! nl>
Date: 2008-12-26 14:01:27
Message-ID: 37382E8DCB905042969BA78541F6570624D66B () kwek ! ic ! uva ! nl
[Download RAW message or body]
take a look also at some examples from the book by Reimann et al. (2008). They \
actually load a jpg map (showing coast-line/borders) as a background plot (method \
"plotbg" in package "StatDA"):
6.4 Spatial Trends
http://www.statistik.tuwien.ac.at/StatDA/R-scripts/page138.html
8.9 Data Subsets in Maps
http://www.statistik.tuwien.ac.at/StatDA/R-scripts/page157.html
HTH
Tom Hengl
http://spatial-analyst.net
________________________________
From: r-sig-geo-bounces@stat.math.ethz.ch on behalf of Jon Loehrke
Sent: sri 12/24/2008 7:01
To: r-sig-geo@stat.math.ethz.ch
Subject: [R-sig-Geo] adding a background shape to ssplot
Greetings and Happy Holidays!
I am an ~experienced R user but new to spatially oriented packages. I
have been trying to add a 'background' shape to a ssplot. My example
is to add a background state map to the sids data.
My 2 questions, 1) What am I missing with the spplot - lattice
interaction[this seems like it should be simple]?, and 2) is there a
better way to add the 'background' map if the object is a
SpatialPolygonsDataFrame?
#Examples mostly from http://r-spatial.sourceforge.net/gallery/
#Library's required for example
library(sp)
library(grid)
library(lattice)
library(maps)
library(RColorBrewer)
library(maptools)
#First a Basic plot and an added map
nc1 <- readShapePoly(system.file("shapes/sids.shp", package="maptools")
[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
names(nc1)
rrt <- nc1$SID74/nc1$BIR74
brks <- quantile(rrt, seq(0,1,1/7))
cols <- grey((length(brks):2)/length(brks))
dens <- (2:length(brks))*3
plot(nc1, col=cols[findInterval(rrt, brks, all.inside=TRUE)])
# add US State map
map('state', add=TRUE, xlim=par('usr')[1:2], ylim=par('usr')[3:4])
#This works fine, but I have issues when using spplot.
example
nc1$f = factor(sample(1:5,100,replace=T),labels=letters[1:5])
nc1$g = factor(sample(1:5,100,replace=T),labels=letters[6:10])
spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),
scales=list(draw = TRUE))
# create a custom panel to add a map polygon to lattice plot
panel.mapper <- function(...){
library(maps)
mp<-map('state', fill=TRUE, plot=FALSE)
lpolygon(mp$x, mp$y, col='gray', ...)
}
#The panel mapper appears to work
spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),
scales=list(draw = TRUE), panel=function(...) {
panel.mapper()
})
#However I can seem to pass the polygon colors argument through ssplot
spplot(nc1, c("f","g"), col.regions=brewer.pal(10, "Set3"),
scales=list(draw = TRUE),
panel=function(...) {
panel.mapper()
sp.polygons(nc1)
}
)
Thanks for the help and happiest holidays.
Jon Loehrke
Graduate Research Assistant
Department of Fisheries Oceanography
School for Marine Science and Technology
University of Massachusetts
200 Mill Road, Suite 325
Fairhaven, MA 02719
jloehrke@umassd.edu
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-apple-darwin8.11.1
locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets
methods base
other attached packages:
[1] lattice_0.17-17 RColorBrewer_1.0-2 maps_2.0-40
maptools_0.7-15 foreign_0.8-29 sp_0.9-28
loaded via a namespace (and not attached):
[1] tools_2.8.1
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic