Learn R Programming

McSpatial (version 1.1.1)

mappoints: Maps showing points on a shape file

Description

Uses the classInt package to show a color ramp of points placed on a shape file map

Usage

mappoints(shpfile,longvar,latvar,pointvar,sampvar=NULL,nclass=8,
  col="RdBu",pointsize=.6,colreverse=TRUE,xlimfact=c(1,1),ylimfact=c(1,1),
  legendloc=NULL,legendsize=.75,legenddigits=4,title=NULL)

Arguments

shpfile
The shape file, a polygon map showing areas.
longvar
Longitude variable for the point data, in degrees.
latvar
Latitude variable for the point data, in degrees.
pointvar
The variable to be mapped.
sampvar
A variable indiciating which observations to include in the map. Tracts for which sampvar=F will not be drawn.
nclass
The number of classes used when mapping pointvar. Default: nclass=8.
col
Color scheme for the map. All of RColorBrewer's schemes are available, e.g., "Blues", "BuGn", "BuPu", and "GnBu". Default: "RdBu"
pointsize
The size of the points drawn on the map. Fed directly to the cex option for the points command. Default: pointsize=.6.
colreverse
If TRUE, reverses the order of the color ramp for the col options. Default: colreverse=T.
xlimfact
A vector of factors used to adjust the limits for the box around the map. The limits for the x-axis (i.e., the longitudes) are xlim=c(min(longvar),max(longvar))*xlimfact. Since the geographic coordinates are expressed in degrees, small adjustments wil
ylimfact
The counterpart to xlimfact for the y (i.e., latitude) axis. Default: ylimfact = c(1,1).
legendloc
The location for the legend, e.g., "topleft" or "bottom". By default, the legend is omitted.
legendsize
The font size for the legend. Fed directly to the cex option for the legend command. Default: legendsize=.75.
legenddigits
Number of significant digits for the numbers shown in the legend. Default: legenddigits = 4.
title
A title for the map.

See Also

mapoverlay mapplot

Examples

Run this code
library(maptools)
cmap <- readShapePoly(system.file("maps/CookCensusTracts.shp",
  package="McSpatial"))
carea <- cmap$CAREA=="Albany Park"|cmap$CAREA=="Edgewater"|
  cmap$CAREA=="Edison Park"|cmap$CAREA=="Forest Glen"|
  cmap$CAREA=="Jefferson Park"|cmap$CAREA=="Lincoln Square"|
  cmap$CAREA=="North Park"|cmap$CAREA=="Norwood Park"|
  cmap$CAREA=="Rogers Park"|cmap$CAREA=="Uptown"|
  cmap$CAREA=="West Ridge"
carea[is.na(carea)] <- FALSE

data(matchdata)
mappoints(cmap,matchdata$longitude,matchdata$latitude,matchdata$lnprice,
  sampvar=carea,legendloc="bottomleft",title="Location of Home Sales")

Run the code above in your browser using DataLab