add_continuous_breaks: Add continuous scale to a map

Description Usage Arguments Examples

Description

Map a continuous numerical variables by cutting it into class intervals.

Usage

1
2
add_continuous_breaks(map, var, palette = "viridis", direction = 1,
  n_breaks = 5, style = "pretty", na_color = "#b8b8b8")

Arguments

map

A d3_map htmlwidget object.

var

Variable to map.

palette

Color palette, you can use Viridis or Brewer color palette.

direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

n_breaks

Number of breaks to cut data (depending on style, number of breaks can be re-computed).

style

Style for computing breaks, see classIntervals.

na_color

Color to use for missing value(s).

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
49
50
51
52
53
54
55
library( r2d3maps )
library( rnaturalearth )

# data
tunisia <- ne_states(country = "tunisia", returnclass = "sf")

# fake percentage
tunisia$p <- sample.int(100, nrow(tunisia))

# fake continuous var
tunisia$foo <- sample.int(1e5, nrow(tunisia))


# Tunisia
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "p")

# different color palette
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "p", palette = "Greens")

# legend
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "p",
                       palette = "inferno",
                       direction = -1) %>%
  add_legend(title = "Percentage", suffix = "%")



# different style of breaks

# equal
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "foo",
                       palette = "inferno",
                       direction = -1,
                       style = "equal") %>%
  add_legend(title = "foo", d3_format = ".0f")

# quantile
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "foo",
                       palette = "inferno",
                       direction = -1,
                       style = "quantile") %>%
  add_legend(title = "foo", d3_format = ".0f")

# pretty
d3_map(shape = tunisia) %>%
  add_continuous_breaks(var = "foo",
                       palette = "inferno",
                       direction = -1,
                       style = "pretty") %>%
  add_legend(title = "foo", d3_format = ".0f")

dreamRs/r2d3maps documentation built on May 25, 2019, 8:17 a.m.