Title: | Plot Map of the Indian Subcontinent |
---|---|
Description: | Get map data frames for the Indian subcontinent with different region levels (e.g., district, state). The package also offers convenience functions for plotting choropleths, visualizing spatial data, and handling state/district codes. |
Authors: | Shubham Dutta [aut, cre, cph] |
Maintainer: | Shubham Dutta <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1.9000 |
Built: | 2025-02-13 04:13:23 UTC |
Source: | https://github.com/shubhamdutta26/mapindia |
Central Zonal Council comprises of Chhattisgarh, Madhya Pradesh, Uttarakhand and Uttar Pradesh.
.central
.central
An object of class character
of length 4.
See https://en.wikipedia.org/wiki/Central_Zonal_Council
plot_india(include = .central, labels = TRUE)
plot_india(include = .central, labels = TRUE)
Eastern Zonal Council comprises of Bihar, Jharkhand, Odisha, and West Bengal.
.east
.east
An object of class character
of length 4.
See https://en.wikipedia.org/wiki/Eastern_Zonal_Council
plot_india(include = .east, labels = TRUE)
plot_india(include = .east, labels = TRUE)
Northern Zonal Council comprises of Chandigarh, Delhi, Haryana, Himachal Pradesh, Jammu and Kashmir, Ladakh, Punjab, and Rajasthan.
.north
.north
An object of class character
of length 8.
See https://en.wikipedia.org/wiki/Northern_Zonal_Council
plot_india(include = .north, labels = TRUE)
plot_india(include = .north, labels = TRUE)
North Eastern Council comprises of Assam, Arunachal Pradesh, Manipur, Meghalaya, Mizoram, Nagaland and Tripura.
.northeast
.northeast
An object of class character
of length 7.
See https://en.wikipedia.org/wiki/North_Eastern_Council
plot_india(include = .northeast, labels = TRUE)
plot_india(include = .northeast, labels = TRUE)
Southern Zonal Council comprises of Andhra Pradesh, Karnataka, Kerala, Puducherry, Tamil Nadu, and Telangana.
.south
.south
An object of class character
of length 6.
See https://en.wikipedia.org/wiki/Southern_Zonal_Council
plot_india(include = .south, labels = TRUE)
plot_india(include = .south, labels = TRUE)
Southern Zonal Council comprises of Andhra Pradesh, Karnataka, Kerala, Puducherry, Tamil Nadu, and Telangana. Andaman and Nicobar and Lakshadweep are special invitees of the Southern Zonal Council.
.southsp
.southsp
An object of class character
of length 8.
See https://en.wikipedia.org/wiki/Southern_Zonal_Council
plot_india(include = .southsp, labels = TRUE)
plot_india(include = .southsp, labels = TRUE)
Western Zonal Council comprises of Dadra and Nagar Haveli and Daman and Diu, Goa, Gujarat, and Maharashtra.
.west
.west
An object of class character
of length 5.
See https://en.wikipedia.org/wiki/Western_Zonal_Council
plot_india(include = .west, labels = TRUE)
plot_india(include = .west, labels = TRUE)
Retrieve states or districts using codes
code_info(code11, sortAndRemoveDuplicates = FALSE) ## S3 method for class 'numeric' code_info(code11, sortAndRemoveDuplicates = FALSE) ## S3 method for class 'character' code_info(code11, sortAndRemoveDuplicates = FALSE)
code_info(code11, sortAndRemoveDuplicates = FALSE) ## S3 method for class 'numeric' code_info(code11, sortAndRemoveDuplicates = FALSE) ## S3 method for class 'character' code_info(code11, sortAndRemoveDuplicates = FALSE)
code11 |
A one to three digit, either |
sortAndRemoveDuplicates |
Whether or not to sort the output and remove
duplicates. By default, the output will be returned in the order of
the values provided to the |
A data frame with the states or counties and the associated codes.
If 'codes' is omitted, the data frame containing all available states is returned.
[codes()]
code_info(2) code_info("02") code_info(c("02", "03", "04")) code_info(19335) code_info(c("19335", "19337"), sortAndRemoveDuplicates = TRUE)
code_info(2) code_info("02") code_info(c("02", "03", "04")) code_info(19335) code_info(c("19335", "19337"), sortAndRemoveDuplicates = TRUE)
Each state and district has a unique two and five digit code code respectively. Use this function to obtain the code for a state or district.
codes(state, district = c())
codes(state, district = c())
state |
The state(s) for which to obtain a code(s). Can be entered as either a state abbreviation or full name (case-insensitive). 'state' can be entered as either a single state or a vector of states. If 'state' is a vector, 'district' must be omitted. |
district |
The county for which to obtain a code. Can be entered with or without "district" (case-insensitive). |
State and district codes are two and five digit codes, respectively. They uniquely identify all states and districts within India. The state and district codes is merged into one code with 5 digits. The first two digits of the five digit district codes correspond to the state that the district belongs to.
The code(s) of given state
or district
.
If only states are entered, a vector of length equal to the number of states is returned. If any states are not found or are invalid, 'NA' is returned in their place.
If a state and district are entered, a single value with the code for the given district is returned. If the district is invalid for the given state, an error is thrown.
If both 'state' and 'district' are omitted, the entire list of available codes are returned, sorted by the state's abbreviation.
A state
must be included when searching for district
,
otherwise multiple results may be returned for duplicate district names.
[code_info()]
codes() codes("AP") codes("Tamil Nadu") codes(c("AP", "WB", "TN")) codes("WB", district = "Kolkata") codes(state = "Uttarakhand", district = "Nainital") codes(state = "RJ", district = "Pratapgarh")
codes() codes("AP") codes("Tamil Nadu") codes(c("AP", "WB", "TN")) codes("WB", district = "Kolkata") codes(state = "Uttarakhand", district = "Nainital") codes(state = "RJ", district = "Pratapgarh")
Retrieve India map data
map_india( regions = c("states", "state", "districts", "district"), include = c(), exclude = c() )
map_india( regions = c("states", "state", "districts", "district"), include = c(), exclude = c() )
regions |
The region breakdown for the map, can be one of
( |
include |
The regions to include in the resulting map. If |
exclude |
The regions to exclude in the resulting map. If |
A data frame of India map coordinates divided by the desired regions
.
[mapindiatools::map_india()] of which this function is a wrapper for.
str(map_india()) df <- map_india(regions = "districts") states <- map_india(include = c("WB", "NCT", "AP"))
str(map_india()) df <- map_india(regions = "districts") states <- map_india(include = c("WB", "NCT", "AP"))
Join district or state level data to India mapping data
map_using_data(data, values = "values", include = c(), exclude = c(), na = NA)
map_using_data(data, values = "values", include = c(), exclude = c(), na = NA)
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 |
values |
The name of the column that contains the values to be associated
with a given region. The default is |
include |
The regions to include in the resulting map. If |
exclude |
The regions to exclude in the resulting map. If |
na |
The value to be inserted for states or districts that don't have
a value in |
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()].
[plot_india()]
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)
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)
This coordinate reference system (CRS) represents
the canonical projection used by the mapindia
package. It can
be used to transform shape files, spatial points, spatial data
frames, etc. to the same coordinate representation that is used
by the plot_india
function.
mapindia_crs()
mapindia_crs()
An 'sf::st_crs' object representing the Coordinate Reference System (CRS) for India, specifically EPSG:4326 (WGS 84). This CRS uses latitude and longitude coordinates and is commonly used for geographic data.
mapindia_crs()
mapindia_crs()
Converting a spatial object of map coordinates will allow those points to line up with the regular mapindia plot by applying the same World Geodetic System 1984 projection to those points as well.
The input 'data' is assumed to contain longitude and latitude coordinates by default. If this is not the case, provide an [sf::st_crs] object to the 'crs' parameter with the appropriate coordinate reference system.
mapindia_transform(data, ...) ## S3 method for class 'sf' mapindia_transform(data, ...) ## S3 method for class 'data.frame' mapindia_transform(data, ..., input_names = c("lon", "lat"))
mapindia_transform(data, ...) ## S3 method for class 'sf' mapindia_transform(data, ...) ## S3 method for class 'data.frame' mapindia_transform(data, ..., input_names = c("lon", "lat"))
data |
A data frame containing coordinates in a two column format where the first column represents longitude and the second data frame represents latitude. The names of the data frame column do not matter, just that the order of the columns is kept intact. |
... |
Additional parameters passed onto [sf::st_as_sf]. By default, 'crs = sf::st_crs(4326)' is used, implying longitude and latitude coordinates. |
input_names |
A character vector of length two which specifies the longitude and latitude columns of the input data (the ones that should be transformed), respectively. Only required if the input data is a 'data.frame' object. Defaults to 'c("lon", "lat")'. |
An 'sf' object containing the transformed coordinates from the input data frame with the World Geodetic System 1984 projection applied. The transformed columns will be appended to the data frame so that all original columns should remain intact.
data <- data.frame( lon = c(77.10, 88.36, 80.27, 72.87, 77.59, 78.03), lat = c(28.71, 22.57, 13.08, 19.07, 12.97, 30.31), pop = c(8398748, 2325502, 3990456, 2705994, 32113, 347397) ) # Transform data transformed_data <- mapindia_transform(data) # Plot transformed data on map library(ggplot2) plot_india() + geom_sf( data = transformed_data, aes(size = pop), color = "red", alpha = 0.5 )
data <- data.frame( lon = c(77.10, 88.36, 80.27, 72.87, 77.59, 78.03), lat = c(28.71, 22.57, 13.08, 19.07, 12.97, 30.31), pop = c(8398748, 2325502, 3990456, 2705994, 32113, 347397) ) # Transform data transformed_data <- mapindia_transform(data) # Plot transformed data on map library(ggplot2) plot_india() + geom_sf( data = transformed_data, aes(size = pop), color = "red", alpha = 0.5 )
Conveniently plot basic India map
plot_india( regions = c("states", "state", "districts", "district"), include = c(), exclude = c(), data = data.frame(), values = "values", theme = theme_map(), labels = FALSE, label_color = "black", label_size = 4, ... )
plot_india( regions = c("states", "state", "districts", "district"), include = c(), exclude = c(), data = data.frame(), values = "values", theme = theme_map(), labels = FALSE, label_color = "black", label_size = 4, ... )
regions |
The region breakdown for the map, can be one of
( |
include |
The regions to include in the resulting map. If |
exclude |
The regions to exclude in the resulting map. If |
data |
A data frame containing values to plot on the map. This
parameter should be a data frame consisting of two columns,
a code (2 characters for state, 3 characters for district)
and the value that should be associated with that region. The
columns of |
values |
The name of the column that contains the values to be associated
with a given region. The default is |
theme |
The theme that should be used for plotting the map. The default
is |
labels |
Whether or not to display labels on the map. Labels are not displayed by default. |
label_color |
The color of the labels to display. Corresponds to the |
label_size |
The size of the labels to display. Corresponds to the |
... |
Other arguments to pass to [ggplot2::aes()]. These are
often aesthetics, used to set an aesthetic to a fixed value, like |
A [ggplot2::ggplot] object that contains a basic
US map with the described parameters. Since the result is a ggplot
object, it can be extended with more [ggplot2::Geom] layers, scales, labels,
themes, etc.
[indiamap], [ggplot2::theme()]
plot_india() plot_india(regions = "states") plot_india(regions = "districts") # Output is ggplot object so it can be extended # with any number of ggplot layers library(ggplot2) plot_india(include = c("GJ", "MH", "MP", "UP")) + labs(title = "Indian States")
plot_india() plot_india(regions = "states") plot_india(regions = "districts") # Output is ggplot object so it can be extended # with any number of ggplot layers library(ggplot2) plot_india(include = c("GJ", "MH", "MP", "UP")) + labs(title = "Indian States")
Indian Population (census and projections) by states.
The data is formatted for easy merging with output from [mapindia::map_india()].
data(statepop)
data(statepop)
A data frame with 36 rows and 8 variables.
code11
The 2-digit state code.
abbr
The 2-letter state abbreviation.
state
The full state name.
pop_1901
The 1901 population estimate (in number of people).
pop_1951
The 1951 population estimate (in number of people).
pop_2011
The 2011 population estimate (in number of people).
pop_2023
The 2023 population estimate (in number of people).
pop_2024
The 2024 population estimate (in number of people).
West Bengal population, sex-ratio, and literacy data for 2011.
The data is formatted for easy merging with output from [mapindia::map_india()].
data(wb_2011)
data(wb_2011)
A data frame with 23 rows and 8 variables.
code11
The 5-digit code corresponding to the district.
abbr
The 2-letter state abbreviation.
district
The full district name.
pop_2011
The 2011 population estimate (in number of people).
pop_increase_2011
The 2011 population increase (percent of people).
sex_ratio_2011
The 2011 sex ratio (females per 100 males).
literacy_per_2011
The 2011 literacy percentage.
pop_2011
The 2011 population density (unknown units).