Description Usage Arguments Examples
Map a continuous numerical variables by cutting it into class intervals.
1 2 | add_continuous_breaks(map, var, palette = "viridis", direction = 1,
n_breaks = 5, style = "pretty", na_color = "#b8b8b8")
|
map |
A |
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 |
Style for computing breaks, see |
na_color |
Color to use for missing value(s). |
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.