topogram_select: Select menu to update 'topogram()'

Description Usage Arguments Examples

View source: R/topogram_select.R

Description

Use in RMarkdown documents to update a topogram() dynamically.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
topogram_select(
  topogramId,
  sfobj,
  values,
  label = "{value}",
  palette = "viridis",
  rescale_to = c(1, 1000),
  n_iteration = 10,
  width = NULL
)

Arguments

topogramId

The elementId of the topogram() to update.

sfobj

An sf object. For the time being, shape must be projected in Mercator (CRS 4326).

values

Parameters to construct cartograms, can be:

  • a character vector of variable to use

  • a named list where names will be used in select menu and values as variable

  • a list of lists where each sub-list can contain: value (variable), text (label for select menu), palette, labels (parameters specific for the variable considered)

label

glue string to be used in tooltip, you can use HTML tags in it.

palette

Name of a color palette, such as "viridis", "Blues", ... Or a function to map data values to colors, see scales::col_numeric().

rescale_to

Rescale value to distort topology to a specified range, use NULL to use values as is.

n_iteration

Number of iterations to run the algorithm for. Higher numbers distorts the areas closer to their associated value, at the cost of performance.

width

A numeric input in pixels.

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
56
57
58
59
60
61
62
63
64
library(topogram)
library(htmltools)

# normally, you would use the following in RMarkdown

browsable(tagList(
  # Select menu
  topogram_select(
    topogramId = "ID",
    sfobj = world,
    values = list(
      "Population" = "pop_est",
      "GDP" = "gdp_md_est", 
      "CO2 emissions (1990)" = "co2_emissions_1990", 
      "CO2 emissions (2020)" = "co2_emissions_2020", 
      "Share of electricity production from renewables" = "renewables_percent_electricity"
    ),
    label = "{name} : {value}"
  ),
  
  # Topogram
  topogram(
    sfobj = world,
    value = "pop_est", 
    label = "{name} : {value}",
    elementId = "ID"
  )
), value = interactive())


# specific options according to variables
browsable(tagList(
  # Select menu
  topogram_select(
    topogramId = "ID",
    sfobj = world,
    values = list(
      list(
        text = "Population", 
        value = "pop_est", 
        palette = "Greens", 
        label = "{name} : {value} inhabitants"
      ),
      list(
        text = "GDP",
        value = "gdp_md_est", 
        palette = "Blues", 
        label = "{name} : ${value}",
        labs = list(title = "GDP", subtitle = "estimate, in 2017")
      )
    ),
    label = "{name} : {value}"
  ),
  
  # Topogram
  topogram(
    sfobj = world,
    value = "pop_est", 
    elementId = "ID",
    # you have to specify parameters for initializing topogram
    palette = "Greens",
    label = "{name} : {value} inhabitants"
  )
), value = interactive())

dreamRs/topogRam documentation built on Dec. 16, 2021, 6:47 p.m.