R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("maps-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('maps') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "area.map" > > ### * area.map > > flush(stderr()); flush(stdout()) > > ### Name: area.map > ### Title: Area of projected map regions > ### Aliases: area.map > ### Keywords: dplot > > ### ** Examples > > # because the projection is rectangular, these are not true areas on the globe. > m = map("state", fill = TRUE, plot = FALSE) > area.map(m) Warning in areaSqMiles(proj) : sq.mile correction unavailable for no projection [1] 816.295 > area.map(m, ".*dakota") Warning in areaSqMiles(proj) : sq.mile correction unavailable for no projection [1] 44.56549 > area.map(m, c("North Dakota", "South Dakota")) Warning in areaSqMiles(proj) : sq.mile correction unavailable for no projection North Dakota South Dakota 21.89865 22.66685 > > if(require(mapproj)) { + # true areas on the globe + m = map("state", proj="bonne", param=45, fill=TRUE, plot=FALSE) + # North Dakota is listed as 70,704 square miles + area.map(m, "North Dakota") + } Loading required package: mapproj [1] 70962.8 > > > > cleanEx(); ..nameEx <- "county" > > ### * county > > flush(stderr()); flush(stdout()) > > ### Name: county > ### Title: United States County Map > ### Aliases: county countyMapEnv > ### Keywords: datasets > > ### ** Examples > > map('county', 'iowa', fill = TRUE, col = palette()) > > > > cleanEx(); ..nameEx <- "france" > > ### * france > > flush(stderr()); flush(stdout()) > > ### Name: france > ### Title: France Map > ### Aliases: france franceMapEnv > ### Keywords: datasets > > ### ** Examples > > map('france', fill = TRUE, col = 1:10) > > > > cleanEx(); ..nameEx <- "identify.map" > > ### * identify.map > > flush(stderr()); flush(stdout()) > > ### Name: identify.map > ### Title: Identify regions on a map > ### Aliases: identify.map > ### Keywords: iplot > > ### ** Examples > > identify(map("state", fill = TRUE, col = 0)) character(0) > if(require(mapproj)) + identify(map("world", proj = "lagrange", fill = TRUE, col = 0)) Loading required package: mapproj character(0) > > > > cleanEx(); ..nameEx <- "italy" > > ### * italy > > flush(stderr()); flush(stdout()) > > ### Name: italy > ### Title: Italy Map > ### Aliases: italy italyMapEnv > ### Keywords: datasets > > ### ** Examples > > map('italy', fill = TRUE, col = 1:10) > > > > cleanEx(); ..nameEx <- "map" > > ### * map > > flush(stderr()); flush(stdout()) > > ### Name: map > ### Title: Draw Geographical Maps > ### Aliases: map > ### Keywords: hplot > > ### ** Examples > > map() # low resolution map of the world > map('usa') # national boundaries > map('county', 'new jersey') # county map of New Jersey > map('state', region = c('new york', 'new jersey', 'penn')) # map of three states > map("state", ".*dakota", border = 0) # map of the dakotas > map.axes() # show the effect of border = 0 > if(require(mapproj)) + map('state', proj = 'bonne', param = 45) # Bonne equal-area projection of states Loading required package: mapproj > > # names of the San Juan islands in Washington state > map('county', 'washington,san', names = TRUE, plot = FALSE) [1] "washington,san juan:lopez island" "washington,san juan:orcas island" [3] "washington,san juan:san juan island" > > # national boundaries in one linetype, states in another > # (figure 5 in the reference) > map("state", interior = FALSE) > map("state", boundary = FALSE, lty = 2, add = TRUE) > > # plot the ozone data on a base map > # (figure 4 in the reference) > data(ozone) > map("state", xlim = range(ozone$x), ylim = range(ozone$y)) > text(ozone$x, ozone$y, ozone$median) > box() > > > > cleanEx(); ..nameEx <- "map.axes" > > ### * map.axes > > flush(stderr()); flush(stdout()) > > ### Name: map.axes > ### Title: Draw Axes on Geographical Maps > ### Aliases: map.axes > ### Keywords: hplot > > ### ** Examples > > map("state") > map.axes() > > > > cleanEx(); ..nameEx <- "map.cities" > > ### * map.cities > > flush(stderr()); flush(stdout()) > > ### Name: map.cities > ### Title: Add Cities to Existing Map > ### Aliases: map.cities > ### Keywords: hplot > > ### ** Examples > > map("world", "China") > map.cities(country = "China", capitals = 2) > > > > cleanEx(); ..nameEx <- "map.scale" > > ### * map.scale > > flush(stderr()); flush(stdout()) > > ### Name: map.scale > ### Title: Add Scale to Existing Unprojected Map > ### Aliases: map.scale > ### Keywords: hplot > > ### ** Examples > > map("world", "China") > map.scale() > > > > cleanEx(); ..nameEx <- "map.text" > > ### * map.text > > flush(stderr()); flush(stdout()) > > ### Name: map.text > ### Title: Draw a map with labeled regions > ### Aliases: map.text > ### Keywords: hplot > > ### ** Examples > > map.text("world", "ira") # iran and iraq > map.text("state", "penn") > map.text("county", "penn") # Pennsylvania counties > map.text("county", "new jersey") # New Jersey counties > > > > cleanEx(); ..nameEx <- "map.where" > > ### * map.where > > flush(stderr()); flush(stdout()) > > ### Name: map.where > ### Title: Locate points on a map > ### Aliases: map.where > ### Keywords: iplot > > ### ** Examples > > # NYC > map.where("state", -73.8, 41) [1] "new york:main" > # Auckland > map.where("nz", 174.6, -36.92) [1] "North.Island " > # find both in the world (takes a while) > map.where(x = c(174.6, -73.8), y = c(-36.92, 41)) [1] "New Zealand:North Island" "USA" > # with a map object: > m = map("state", "new york", fill = TRUE, plot = FALSE) > map.where(m, -73.8, 41) [1] "new york:main" > > > > cleanEx(); ..nameEx <- "match.map" > > ### * match.map > > flush(stderr()); flush(stdout()) > > ### Name: match.map > ### Title: Index map regions > ### Aliases: match.map > ### Keywords: dplot > > ### ** Examples > > # filled map showing Republican vote in 1900 > # (figure 6 in the reference) > data(state, package = "base") Warning in data(state, package = "base") : datasets have been moved from package 'base' to package 'datasets' > data(votes.repub) > state.to.map <- match.map("state", state.name) > x <- votes.repub[state.to.map, "1900"] > gray.colors <- function(n) gray(rev(0:(n - 1))/n) > color <- gray.colors(100)[floor(x)] > map("state", fill = TRUE, col = color); map("state", add = TRUE) > > > > cleanEx(); ..nameEx <- "nz" > > ### * nz > > flush(stderr()); flush(stdout()) > > ### Name: nz > ### Title: New Zealand Basic Map > ### Aliases: nz nzMapEnv > ### Keywords: datasets > > ### ** Examples > > map('nz') > map('nz', xlim = c(166, 179), ylim = c(-48, -34)) > > > > cleanEx(); ..nameEx <- "smooth.map" > > ### * smooth.map > > flush(stderr()); flush(stdout()) > > ### Name: smooth.map > ### Title: Smooth out aggregated data > ### Aliases: smooth.map > ### Keywords: dplot > > ### ** Examples > > # compare to the example for match.map > data(state, package = "base") Warning in data(state, package = "base") : datasets have been moved from package 'base' to package 'datasets' > data(votes.repub) > z = votes.repub[, "1900"] > m = map("state", fill = TRUE, plot = FALSE) > # use a small span to fill in, but not smooth, the data > # increase the resolution to get better results > fit = smooth.map(m, z, span = 1/100, merge = TRUE, ave = TRUE) > mat = tapply(fit$z, fit[1:2], mean) > gray.colors <- function(n) gray(rev(0:(n - 1))/n) > par(bg = "blue") > filled.contour(mat, color.palette = gray.colors, nlev = 32, asp = 1) > # another way to visualize: > image(mat, col = gray.colors(100)) > > # for a higher degree of smoothing: > # fit = smooth.map(m, z, merge = TRUE, ave = TRUE) > # interpolation, state averages are preserved: > # fit = smooth.map(m, z, merge = TRUE, ave = TRUE, type = "interp") > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "state" > > ### * state > > flush(stderr()); flush(stdout()) > > ### Name: state > ### Title: United States State Boundaries Map > ### Aliases: state stateMapEnv > ### Keywords: datasets > > ### ** Examples > > map('state', fill = TRUE, col = palette()) > > > > cleanEx(); ..nameEx <- "usa" > > ### * usa > > flush(stderr()); flush(stdout()) > > ### Name: usa > ### Title: United States Coast Map > ### Aliases: usa usaMapEnv > ### Keywords: datasets > > ### ** Examples > > map('usa') > > > > cleanEx(); ..nameEx <- "world" > > ### * world > > flush(stderr()); flush(stdout()) > > ### Name: world > ### Title: Low resolution World Map > ### Aliases: world worldMapEnv > ### Keywords: datasets > > ### ** Examples > > map('world', fill = TRUE, col = 1:10) > > > > cleanEx(); ..nameEx <- "world2" > > ### * world2 > > flush(stderr()); flush(stdout()) > > ### Name: world2 > ### Title: Pacific Centric Low resolution World Map > ### Aliases: world2 world2MapEnv > ### Keywords: datasets > > ### ** Examples > > map('world2', xlim = c(100, 300)) > map.axes() > > > > ### *