Skip to contents

[Maturing]

get_map_fill_data() prepares data to be used as fill in a map.

Usage

get_map_fill_data(
  data,
  col_fill = NULL,
  col_code,
  name_col_value = "n",
  name_col_ref = col_code,
  quiet = FALSE
)

Arguments

data

A tibble with the data to be used as fill.

col_fill

(Optional) A character string with the column name to be used as fill. If NULL, the function will count the number of occurrences of each value in col_code (Default: NULL).

col_code

A character string with the column name to be used as reference.

name_col_value

(Optional) A character string with the name of the column to be used as value (Default: "n").

name_col_ref

(Optional) A character string with the name of the column to be used as reference (Default: col_code).

quiet

(Optional) A logical flag to suppress messages (Default: FALSE).

Value

A tibble.

See also

Other utility functions: fix_postal_code()

Examples

library(dplyr)

data <- tibble(
  state = c("SP", "RJ", "MG", "SP", "RJ", "MG"),
  value = c(1, 2, 3, 4, 5, 6)
)

get_map_fill_data(data, col_fill = NULL, col_code = "state")
#> # A tibble: 3 × 2
#>   state     n
#>   <chr> <int>
#> 1 MG        2
#> 2 RJ        2
#> 3 SP        2

get_map_fill_data(data, col_fill = "value", col_code = "state")
#> ! There are duplicated values in state. value will be aggregated using the mean.
#> # A tibble: 3 × 2
#>   state     n
#>   <chr> <dbl>
#> 1 SP      2.5
#> 2 RJ      3.5
#> 3 MG      4.5