mapPolys: Map polygon data.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Plot a map of polygons, from a spatialPolygonsDataFrame, coloured according to one a specified attribute column.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
mapPolys( mapToPlot = ""
        , nameColumnToPlot = ""
        , numCats = 7
        , xlim=NA
        , ylim=NA
        , mapRegion = "world"
        , catMethod="quantiles"
        , colourPalette= "heat"
        , addLegend=TRUE
        , borderCol = 'grey'
        , mapTitle = 'columnName'
        , oceanCol=NA
        , aspect=1
        , missingCountryCol=NA
        , add=FALSE
        , lwd=0.5                                                    
        ) 

Arguments

mapToPlot

a spatial polygons dataframe (e.g. from joinData2Map()) containing polygons and associated data, if none specified an internal example data is used

nameColumnToPlot

name of column containing the data you want to plot

numCats

number of categories to put the data in, may be modified if this number is incompatible with the catMethod chosen

xlim

map extents c(west,east), can be overidden by mapRegion

ylim

map extents c(south,north), can be overidden by mapRegion

mapRegion

a country name from getMap()[['NAME']] or 'world','africa','oceania','eurasia','uk' sets map extents, overrides xlim,ylim

catMethod

for categorisation of data "pretty", "fixedWidth", "diverging", "logFixedWidth", "quantiles", "categorical", or a numeric vector defining breaks

colourPalette

string describing the colour palette to use, choice of:

  1. "palette" for the current palette

  2. a vector of valid colours, e.g. =c('red','white','blue') or output from RColourBrewer

  3. one of "heat", "diverging", "white2Black", "black2White", "topo", "rainbow", "terrain", "negpos8", "negpos9"

addLegend

whether to add a legend or not

borderCol

the colour for country borders

mapTitle

title to add to the map, any string or 'columnName' to set it to the name of the data column

oceanCol

a colour for the ocean

aspect

aspect for the map, defaults to 1, if set to 'variable' uses same method as plot.Spatial in sp

missingCountryCol

a colour for missing countries

add

whether to add this map on top of an existing map, TRUE/FALSE

lwd

line width for country borders

Details

Certain catMethod and colourPalette options go well together. e.g. "diverging" and "diverging", "categorical" and "rainbow"

There are two styles of legend available. If catMethod='categorical' or the packages fields and spam are not installed a simple legend with coloured boxes is created. Otherwise a colour bar legend is created. Finer control can be achieved by addMapLegendBoxes or addMapLegend repectively.

Value

invisibly returns a list containing the data and main options used for the map, the list can be passed to addMapLegend or addMapLegendBoxes along with additional options to allow greater flexibility in legend creation.

Author(s)

andy south

See Also

joinData2Map, classInt, RColorBrewer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## this example uses downloaded files
## to run it download the files
## and remove the comment symbols '#' from all the lines starting with a single '#'

## US states map downloaded from :
## http://www2.census.gov/cgi-bin/shapefiles2009/national-files

#inFile <- 'tl_2009_us_stateec.shp'
#sPDF <- readShapePoly(inFile)
#str(sPDF@data)

##################
## use mapPolys to map the sPDF
#mapPolys(sPDF,nameColumnToPlot = "ALANDEC")
#mapPolys(sPDF,nameColumnToPlot = "AWATEREC",mapRegion='North America')

##################
## join some other data to it
## education data downloaded from here as xls then saved as csv
## http://nces.ed.gov/ccd/drpcompstatelvl.asp

#dataFile <- 'SDR071A_xls.csv'
#dF <- read.csv(dataFile,as.is=TRUE)
#str(dF)
## STATENAME
## DRP912 Dropout Rate, Grades 9 through 12

## joining the data to the map
## based upon state names (column NAMEEC in map, and STATENAME in the data)
#sPDF2 <- joinData2Map(dF
#        , nameMap = sPDF
#        , nameJoinIDMap = "NAMEEC"
#        , nameJoinColumnData = "STATENAME")

#################
## plot one of the attribute variables
#mapDevice()# to set nice shape map window
#mapPolys(sPDF2,nameColumnToPlot = "DRP912",mapRegion='North America')


#################
###to map US counties data (Tiger) downloaded from :
##http://www2.census.gov/cgi-bin/shapefiles2009/national-files

#inFile <- 'tl_2009_us_county.shp'
#sPDF <- readShapePoly(inFile)
#str(sPDF@data)
#mapPolys(sPDF,nameColumnToPlot='AWATER',xlim=c(-140,-65), ylim=c(25,45))

rworldmap documentation built on May 2, 2019, 4:50 p.m.