add_choropleth: Add choropleth

Description Usage Arguments Examples

View source: R/add.R

Description

Add choropleth data.

Usage

1
2
3
4
5
6
7
add_choropleth(
  p,
  locations,
  color,
  ...,
  colors = c("#FFEDA0", "#FEB24C", "#F03B20")
)

Arguments

p

a datamaps object.

locations

column containing location names as iso3c.

color

column containing color of each location.

...

any other variable to use for tooltip.

colors

color palette.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
data <- data.frame(name = c("USA", "FRA", "CHN", "RUS", "COG", "DZA"),
    color = round(runif(6, 1, 10)))

data %>%
    datamaps() %>%
    add_choropleth(name, color, colors = c("skyblue", "yellow", "orangered"))

# categorical colors
cat <- data.frame(name = c("USA", "BRA", "COL", "CAN", "ARG", "CHL"),
    col = rep(c("Yes", "No"), 6))

cat %>%
    datamaps(projection = "orthographic") %>%
    add_choropleth(name, col, colors = c("red", "blue"))

# US states
states <- data.frame(st = c("AR", "NY", "CA", "IL", "CO", "MT", "TX"),
    val = c(10, 5, 3, 8, 6, 7, 2))

states %>%
    datamaps(scope = "usa", default = "lightgray") %>%
    add_choropleth(st, val) %>%
    add_labels()

JohnCoene/datamaps documentation built on Aug. 30, 2020, 7:20 a.m.