For future reference, you may want to look at the symbols function instead of points (for this example points works, but symbols gives more options/flexibility, the my.symbols function in the TeachingDemos package gives even more options for adding symbols to a plot).
Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of eric.archer > Sent: Wednesday, May 20, 2009 4:39 PM > To: r-help@r-project.org > Subject: Re: [R] combining xYplot with map > > I'll retract my request for help. I managed to solve the problem by > calling map followed by a call to points after rescaling the cex. Its > the kind of solution that deserves a head-slap. > > library(Hmisc) > library(maps) > > sample.data <- data.frame(lat = c(12.1667, 14.6333, -6.874, 2.6167, > 14.6833, > 11.2, 3.2667, 11.4167, -13.8623, 13.1667), lon = c(-126.25, -103.4667, > -88.4572, -93.65, -97.7, -88.65, -111.0167, -119.7333, -100.0748, > -108.0333), exp.index = c(23.6266244576543, 2.06824648038330, > 0, 1.46378849121688, 24.1824663424805, 0, 0.364600074527829, > 4.468039274638, 0.543833744085446, 18.2301918845932)) > > xlim <- c(-150, -80) > ylim <- c(-5, 30) > cex.range <- c(1, 5) > exp.range <- range(sample.data$exp.index) > exp.cex <- diff(cex.range) * sample.data$exp.index / exp.range[2] + > cex.range[1] > map("world", fill = TRUE, col = "gray", xlim = xlim, ylim = ylim) > points(sample.data$lon, sample.data$lat, pch = 21, cex = exp.cex) > > > > eric.archer wrote: > > I'm using xYplot to create a bubble plot of values that I'd like to > > visualize on top of a filled-in map of the coast, but I'm too much of > > a lattice (which I understand xYplot is built on) and mapping newbie > > to figure out how to begin to make this happen. Below is some sample > > code that doesn't work but illustrates my goal. Any pointers anyone > > has would be much appreciated. I'm using R v2.9.0 on Windows with > > Hmisc v3.6-0 and maps v2.1-0. > > > > Cheers, > > eric > > > > library(Hmisc) > > library(maps) > > > > sample.data <- data.frame(lat = c(12.1667, 14.6333, -6.874, 2.6167, > > 14.6833, > > 11.2, 3.2667, 11.4167, -13.8623, 13.1667), lon = c(-126.25, - > 103.4667, > > -88.4572, -93.65, -97.7, -88.65, -111.0167, -119.7333, -100.0748, > > -108.0333), exp.index = c(23.6266244576543, 2.06824648038330, > > 0, 1.46378849121688, 24.1824663424805, 0, 0.364600074527829, > > 4.468039274638, 0.543833744085446, 18.2301918845932)) > > > > xlim <- c(-150, -80) > > ylim <- c(-5, 30) > > print(xYplot(lat ~ lon, data = sample.data, size = > sample.data$exp.index, > > xlim = xlim, ylim = ylim > > )) > > map("world", fill = TRUE, col = "gray", xlim = xlim, ylim = ylim, add > > = TRUE) > > > > -- > > Eric Archer, Ph.D. > Southwest Fisheries Science Center > National Marine Fisheries Service > 3333 North Torrey Pines Court > La Jolla, CA 92037-1022 > 858-546-7121 (work) > 858-546-7003 (FAX) > > ETP Cetacean Assessment Program: http://swfsc.noaa.gov/prd-etp.aspx > Population ID Program: http://swfsc.noaa.gov/prd-popid.aspx > > > "Innocence about Science is the worst crime today." > - Sir Charles Percy Snow > > "Lighthouses are more helpful than churches." > - Benjamin Franklin > > "...but I'll take a GPS over either one." > - John C. "Craig" George > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.