Re: [R] maps and lattice

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Tue, 05 Feb 2008 14:43:42 -0800

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



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. Received on Tue 05 Feb 2008 - 22:45:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 23:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive