Learn R Programming

GADMTools (version 3.9-1)

choropleth: Draw a choropleth on selected regions

Description

Drawing a choropleth (colored regions based on data values) with GADMTools is straightforward. You just have to select your shape(s) file(s) with gadm_loadcountries, load your data from a csv file for example, and call the choropleth function with the right arguments.

Usage

choropleth (x, data, value=NULL, breaks = NULL, steps = 5, adm.join=NULL,
            legend = NULL, labels = NULL, palette=NULL,
            title="", subtitle = NULL, caption = NULL)

Arguments

x

Object gadm_sf or gadm_sp

data

data.frame - data to plot

value

String - the name of the column in the data.frame we want to plot (eg: an incidence in epidemiology studies)

breaks

Vector of breaks values or a Sring name of a function from classIntervals (one of "sd", "equal", "pretty", "quantile", "kmeans", "hclust", "bclust", "fisher", or "jenks")

steps

Integer - number of breaks. Default = 5. If breaks is NOT NULL this value is used internally with cut().

adm.join

String - the name in your dataset joined with the field NAME_X of the map, where X is the level of the administrative boundaries. For instance if the level is about 'Districts' of a country, and your dataset has a field named "Study_Location" containing a list of districts, just do adm.join = "Study_Location".

legend

String - legend title. Default NULL.

labels

String vector labels for the legend. Default NULL

palette

String - An RColorBrewer palette name or a String vector vector of colors. Default NULL.

title

String - Title of the plot. Default is an empty string.

subtitle

String - subtitle of the plot. Default is NULL.

caption

String - caaption of the plot. Default is NULL.

Value

Object ggplot2

Details

Since this relase, it's no longer necessary to rename the field of your dataset that is joined with the right field of the map. Just write adm.join="data_field_to_link".

References

----

See Also

classIntervals

Examples

Run this code
# NOT RUN {
library(GADMTools)
data("Corsica")
Cantons <- listNames(Corsica, 4)
pop <- floor(runif(length(Cantons), min=15200, max=23500))
DAT <- data.frame(Cantons, pop)

choropleth(Corsica, DAT,
           adm.join = "Cantons",
           value = "pop",
           breaks = "sd",
           palette="Oranges",
           legend = "Population",
           title="Population Cantons de Corse")
# }

Run the code above in your browser using DataLab