Skip to contents

Join district or state level data to India mapping data

Usage

map_using_data(data, values = "values", include = c(), exclude = c(), na = NA)

Arguments

data

The data that should be joined to a India map. This parameter should be a data frame consisting of two columns, a code (2 characters for state, 5 characters for district where first 2 characters correspond to the respective state) and the value that should be associated with that region. The columns of data must be code or state and the value of the `values` parameter. If both code and state are provided, this function uses the code.

values

The name of the column that contains the values to be associated with a given region. The default is "values".

include

The regions to include in the resulting map. If regions is "states"/"state", the value can be either a state name, abbreviation or code. For districts, the district codes must be provided as there can be multiple districts with the same name. If states are provided in the districts map, only districts in the included states will be returned.

exclude

The regions to exclude in the resulting map. If regions is "states"/"state", the value can be either a state name, abbreviation or code. For districts, the district codes must be provided as there can be multiple districts with the same name. The regions listed in the include parameter are applied first and the exclude regions are then removed from the resulting map. Any excluded regions not present in the included regions will be ignored.

na

The value to be inserted for states or districts that don't have a value in data. This value must be of the same type as the value column of data.

Value

A data frame composed of the map data frame (from [map_india()]) except an extra column containing the values in data is included.

The result can be plotted using [ggplot2::ggplot()] or [plot_india()].

See also

[plot_india()]

Examples

data_01 <- data.frame(code = c("01", "02", "04"), values = c(1, 5, 8))
df <- map_using_data(data_01, na = 0)

data_02 <- data.frame(state = c("AP", "WB", "Tamil Nadu"), values = c(6, 9, 3))
df <- map_using_data(data_02, na = 0)