Description Usage Arguments Details Value Warning Author(s) See Also Examples
Draw a map of country-level data, allowing countries to be coloured, from an
object created in joinCountryData2Map
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | mapCountryData(
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
, nameColumnToHatch = ""
, lwd = 0.5
)
|
mapToPlot |
a spatial polygons dataframe from joinCountryData2Map() containing country polygons and 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 |
method for categorisation of data :
|
colourPalette |
string describing the colour palette to use, choice of:
|
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 |
nameColumnToHatch |
allows hatching of country fills (e.g. to represent uncertainty) , specify a column containing numeric data , highest values will be solid and lower values will have a decreasing density of hatching , new feature more documentation will be added soon |
lwd |
line width for country borders |
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.
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.
will generate unhelpful errors in data categorisation if inappropriate options are chosen, e.g. with catMethod:Quantiles if numCats too high so that unique breaks cannot be defined.
andy south
classInt, RColorBrewer
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 | mapCountryData()
data("countryExData",envir=environment(),package="rworldmap")
sPDF <- joinCountryData2Map(countryExData
, joinCode = "ISO3"
, nameJoinColumn = "ISO3V10"
)
mapCountryData( sPDF
, nameColumnToPlot="BIODIVERSITY"
)
#user defined map colour scheme for categorical data
mapParams <- mapCountryData(nameColumnToPlot='GEO3major'
, catMethod='categorical'
, addLegend='FALSE'
, colourPalette=c('white','green','red','yellow','blue','black')
)
#changing legendText
mapParams$legendText <- c('antarctic','africa','oceania'
,'americas','s.asia','eurasia')
do.call( addMapLegendBoxes, c(mapParams,x='bottom',title="Region",horiz=TRUE))
##showing how rworldmap can be used with the classInt and RColorBrewer packages
library(classInt)
library(RColorBrewer)
#getting example data and joining to a map
data("countryExData",envir=environment(),package="rworldmap")
sPDF <- joinCountryData2Map(countryExData,joinCode = "ISO3"
,nameJoinColumn = "ISO3V10")
#getting class intervals using a 'jenks' classification in classInt package
classInt <- classIntervals( sPDF$EPI, n=5, style="jenks")
catMethod = classInt$brks
#getting a colour scheme from the RColorBrewer package
colourPalette <- brewer.pal(5,'RdPu')
#calling mapCountryData with the parameters from classInt and RColorBrewer
mapParams <- mapCountryData( sPDF, nameColumnToPlot="EPI", addLegend=FALSE
, catMethod = catMethod, colourPalette=colourPalette )
do.call(addMapLegend, c(mapParams
,legendLabels="all"
,legendWidth=0.5
,legendIntervals="data"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.