[R] maps and lattice
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Tue Feb 5 23:43:42 CET 2008
Jon Loehrke said the following on 2/5/2008 2:29 PM:
> Is it possible to place maps onto lattice plots?
>
> With basic plotting you can add a map to a plot
>
> library(lattice)
> long<-c(-69.2, -69.5, -70.1, -70.3)
> lat<-c(41, 41.5, 43.2, 42.8)
> plot(long, lat)
> map('state', c("massachusetts"),add=TRUE)
>
> but is it possible with lattice?
>
>
> library(lattice)
> factor<-c(1,1,2,2)
> xyplot(lat~long|fact)
> ...now what?
>
> I have looked at panel and found through google an extravagant shape
> file export/import to R.
> Is there a simpler fix?
>
> Thank you very much for your help.
>
> Jon
>
> School for Marine Science and Technology
> UMASS-Dartmouth
>
Try this:
library(lattice)
library(maps)
long <- c(-69.2, -69.5, -70.1, -70.3)
lat <- c(41, 41.5, 43.2, 42.8)
fact <- c(1, 1, 2, 2)
xyplot(lat ~ long | fact,
panel = function(...) {
panel.xyplot(...)
mp <- map("state", "massachusetts", plot = FALSE)
lpolygon(mp$x, mp$y)
})
HTH,
--sundar
More information about the R-help
mailing list