Type: | Package |
Title: | Plot Map of the Indian Subcontinent |
Version: | 1.0.1 |
Maintainer: | Shubham Dutta <shubhamdutta26@gmail.com> |
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. |
License: | MIT + file LICENSE |
URL: | https://github.com/shubhamdutta26/mapindia, https://www.shubhamdutta.com/mapindia/ |
BugReports: | https://github.com/shubhamdutta26/mapindia/issues |
Depends: | R (≥ 2.10) |
Imports: | ggplot2, mapindiatools, rlang, sf, vdiffr |
Suggests: | knitr, patchwork, rmarkdown, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2024-11-14 15:15:37 UTC; shubham |
Author: | Shubham Dutta |
Repository: | CRAN |
Date/Publication: | 2024-11-14 16:10:07 UTC |
mapindia: 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.
Author(s)
Maintainer: Shubham Dutta shubhamdutta26@gmail.com (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/shubhamdutta26/mapindia/issues
Central Zonal Council
Description
Central Zonal Council comprises of Chhattisgarh, Madhya Pradesh, Uttarakhand and Uttar Pradesh.
Usage
.central
Format
An object of class character
of length 4.
Details
See https://en.wikipedia.org/wiki/Central_Zonal_Council
Examples
plot_india(include = .central, labels = TRUE)
Eastern Zonal Council
Description
Eastern Zonal Council comprises of Bihar, Jharkhand, Odisha, and West Bengal.
Usage
.east
Format
An object of class character
of length 4.
Details
See https://en.wikipedia.org/wiki/Eastern_Zonal_Council
Examples
plot_india(include = .east, labels = TRUE)
Northern Zonal Council
Description
Northern Zonal Council comprises of Chandigarh, Delhi, Haryana, Himachal Pradesh, Jammu and Kashmir, Ladakh, Punjab, and Rajasthan.
Usage
.north
Format
An object of class character
of length 8.
Details
See https://en.wikipedia.org/wiki/Northern_Zonal_Council
Examples
plot_india(include = .north, labels = TRUE)
Northestern Zonal Council
Description
North Eastern Council comprises of Assam, Arunachal Pradesh, Manipur, Meghalaya, Mizoram, Nagaland and Tripura.
Usage
.northeast
Format
An object of class character
of length 7.
Details
See https://en.wikipedia.org/wiki/North_Eastern_Council
Examples
plot_india(include = .northeast, labels = TRUE)
Southern Zonal Council (w/o Special invitees)
Description
Southern Zonal Council comprises of Andhra Pradesh, Karnataka, Kerala, Puducherry, Tamil Nadu, and Telangana.
Usage
.south
Format
An object of class character
of length 6.
Details
See https://en.wikipedia.org/wiki/Southern_Zonal_Council
Examples
plot_india(include = .south, labels = TRUE)
Southern Zonal Council (w/ Special invitees)
Description
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.
Usage
.southsp
Format
An object of class character
of length 8.
Details
See https://en.wikipedia.org/wiki/Southern_Zonal_Council
Examples
plot_india(include = .southsp, labels = TRUE)
Western Zonal Council
Description
Western Zonal Council comprises of Dadra and Nagar Haveli and Daman and Diu, Goa, Gujarat, and Maharashtra.
Usage
.west
Format
An object of class character
of length 5.
Details
See https://en.wikipedia.org/wiki/Western_Zonal_Council
Examples
plot_india(include = .west, labels = TRUE)
Retrieve states or districts using codes
Description
Retrieve states or districts using codes
Usage
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)
Arguments
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 |
Value
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.
See Also
[codes()]
Examples
code_info(2)
code_info("02")
code_info(c("02", "03", "04"))
code_info(19335)
code_info(c("19335", "19337"), sortAndRemoveDuplicates = TRUE)
Retrieve codes for either a India state or district
Description
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.
Usage
codes(state, district = c())
Arguments
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). |
Details
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.
Value
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.
Note
A state
must be included when searching for district
,
otherwise multiple results may be returned for duplicate district names.
See Also
[code_info()]
Examples
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")
Gets code11 info for either states or districts depending on input. Helper function for S3 method [code_info()].
Description
Gets code11 info for either states or districts depending on input. Helper function for S3 method [code_info()].
Usage
get_code_info(code, sortAndRemoveDuplicates)
Retrieve India map data
Description
Retrieve India map data
Usage
map_india(
regions = c("states", "state", "districts", "district"),
include = c(),
exclude = c()
)
Arguments
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 |
Value
A data frame of India map coordinates divided by the desired regions
.
See Also
[mapindiatools::map_india()] of which this function is a wrapper for.
Examples
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
Description
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 |
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 |
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)
mapindia coordinate reference system
Description
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.
Usage
mapindia_crs()
Value
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.
Examples
mapindia_crs()
Convert spatial data to mapindia projection
Description
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.
Usage
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"))
Arguments
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")'. |
Value
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.
Examples
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
)
Transform 'sf' coordinates to 'mapindia' transform
Description
Internal function with common functionality for transforming coordinates. Using this function directly is not recommended.
Usage
perform_transform(data, ...)
Conveniently plot basic India map
Description
Conveniently plot basic India map
Usage
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,
...
)
Arguments
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 |
Value
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.
See Also
[indiamap], [ggplot2::theme()]
Examples
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
Description
Indian Population (census and projections) by states.
The data is formatted for easy merging with output from [mapindia::map_india()].
Usage
data(statepop)
Format
A data frame with 36 rows and 8 variables.
Details
-
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).
Merge while maintaining original sort order
Description
Internal function used by [code_info()].
Usage
static_merge(x, y, ...)
See Also
https://stackoverflow.com/a/61560405/7264964
Convenient theme map
Description
This creates a nice map theme for use in [plot_india()]. It originated from the 'ggthemes' package located at this repository: https://github.com/jrnold/ggthemes.
This function was manually rewritten here to avoid the need for another package import.
Usage
theme_map(base_size = 9, base_family = "")
West Bengal population, sex-ratio, and literacy data (2011)
Description
West Bengal population, sex-ratio, and literacy data for 2011.
The data is formatted for easy merging with output from [mapindia::map_india()].
Usage
data(wb_2011)
Format
A data frame with 23 rows and 8 variables.
Details
-
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).