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 [[alternative HTML version deleted]]
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
Hi, I use the spplot function from the sp package, it uses lattice to make spatial plots. The sp-package provides spatial classes for R. See http://r-spatial.sourceforge.net/ for more information on the use of spatial data in R, http://r-spatial.sourceforge.net/gallery/ gives a gallery of spatial plots with the R code it was created by. For questions on spatial data in R the r-sig-geo mailing list is also a good option (https://stat.ethz.ch/mailman/listinfo/r-sig-geo). hope this helps! Paul Jon Loehrke wrote:> 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 > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax: +31302531145 http://intamap.geo.uu.nl/~paul