mapsPERU

October 23, 2025 · View on GitHub

errero Open Source Love Project-Status:Active LinuxMint CRAN-status Downloads DOI made-with-R

mapsPERU is a package that provides datasets with information of the centroids and geographical limits of the regions, departments, provinces and districts of Peru.

Installation :arrow_double_down:

Install mapsPERU from CRAN:

install.packages("mapsPERU")

or install mapsPERU with

library(remotes)
install_github("musajajorge/mapsPERU")

Documentation :books:

The datasets included in this package are:

  • map_REG: Geographic information of the regions of Peru
  • map_DEP: Geographic information of the departments of Peru
  • map_PROV: Geographic information of the provinces of Peru
  • map_DIST: Geographic information of the districts of Peru

Data dictionary

  • map_REG
ColumnTypeDescription
COD_REGIONchrRegion code
REGIONchrRegion name
POBLACION_2025dblProjected population of the region in 2025
coords_xdblLongitude of the centroid of the region
coords_ydblLatitude of the centroid of the region
geometryMULTIPOLYGONMULTIPOLYGON Geometric object

Note: Officially there is no codification for regions, only for departments. Therefore, the codes 150100 for Metropolitan Lima and 159900 for Lima Provinces should be taken as a reference.

  • map_DEP
ColumnTypeDescription
COD_DEPARTAMENTOchrDepartment code
DEPARTAMENTOchrDepartment name
POBLACION_2025dblProjected population of the department in 2025
coords_xdblLongitude of the centroid of the department
coords_ydblLatitude of the centroid of the department
geometryMULTIPOLYGONMULTIPOLYGON Geometric object
  • map_PROV
ColumnTypeDescription
COD_REGIONchrRegion code
COD_DEPARTAMENTOchrDepartment code
COD_PROVINCIAchrProvince code
REGIONchrRegion name
DEPARTAMENTOchrDepartment name
PROVINCIAchrProvince name
POBLACION_2025dblProjected population of the province in 2025
coords_xdblLongitude of the centroid of the province
coords_ydblLatitude of the centroid of the province
geometryMULTIPOLYGONMULTIPOLYGON Geometric object
  • map_DIST
ColumnTypeDescription
COD_REGIONchrRegion code
COD_DEPARTAMENTOchrDepartment code
COD_PROVINCIAchrProvince code
COD_DISTRITOchrDistrict code
REGIONchrRegion name
DEPARTAMENTOchrDepartment name
PROVINCIAchrProvince name
DISTRITOchrDistrict name
REGION_NATURALchrNatural region
POBLACION_2025dblProjected population of the district in 2025
coords_xdblLongitude of the centroid of the district
coords_ydblLatitude of the centroid of the district
geometryMULTIPOLYGONMULTIPOLYGON Geometric object

Usage :muscle:

You do not need to install additional packages to use mapsPERU datasets; however, if you want to see the structure of each dataset with str() or dplyr::glimpse() it is advisable to run library(sf) beforehand.

Use departmental dataset in a map with ggplot2

library(mapsPERU)
df <- map_DEP

library(ggplot2)
library(sf)
ggplot(df, aes(geometry=geometry)) +
  geom_sf(aes(fill=DEPARTAMENTO))

In this example we are using the name of the departments as a categorical variable in the graph. You can combine the mapsPERU data sets with other categorical or numeric variables that you want to plot.

Use the departmental dataset with centroids in a map with ggplot2

Note that mapsPERU also provides geographic information of the centroids, so you can include the names of the departments as labels.

library(mapsPERU)
df <- map_DEP

library(ggplot2)
library(sf)
ggplot(df, aes(geometry=geometry)) +
  geom_sf(aes(fill=DEPARTAMENTO)) +
  geom_text(data=df, aes(coords_x, coords_y, group=NULL, label=DEPARTAMENTO), size=2.5) +
  labs(x="", y="")

Use regional dataset in a map with ggplot2

The centroids dataset not only provides the longitudes and latitudes of each region but also includes the geometry field, which is a multipolygon that will allow us to plot numerical variables on our map.

In this example, we will graph the projected population by region for the year 2025.

library(mapsPERU)
df <- map_REG

library(ggplot2)
library(sf)
ggplot(df, aes(geometry=geometry)) +
  geom_sf(aes(fill=POBLACION_2025/1000000)) +
  scale_fill_gradient (low="#abd9e9", high="#c51b7d", name="Población 2025 (millones)")

Use the regional dataset with centroids in a map with ggplot2

In this example we will show how the use of regional boundaries and centroids datasets facilitates the filtering of specific regions to be displayed on the map.

library(mapsPERU)
df <- map_REG

df <- dplyr::filter(df, REGION=="Lima Metropolitana" |
                      REGION=="Lima Provincias" | REGION=="Callao")

library(ggplot2)
library(sf)
ggplot(df, aes(geometry=geometry)) +
  geom_sf(aes(fill=REGION)) +
  geom_text(aes(coords_x, coords_y, group=NULL, label=REGION), size=3) +
  labs(x="", y="")

Use the provincial dataset in a map with ggplot2

library(mapsPERU)
df <- map_PROV

df$Categoría <- cut(df$POBLACION_2025, right=F, breaks=c(0,100000,500000,1000000,Inf),
                    labels=c("[ 0 - 100 mil >",
                             "[ 100 mil - 500 mil >",
                             "[ 500 mil - 1 millón >",
                             "[ 1 millón - ∞ >"))

colores <- c('#feebe2','#fbb4b9','#f768a1','#ae017e')

library(sf)
library(ggplot2)
ggplot(df, aes(geometry=geometry)) +
  scale_fill_manual(values=colores)+
  geom_sf(aes(fill=Categoría)) 

Use the district dataset in a map with ggplot2

library(mapsPERU)
df <- map_DIST

df$Categoría <- cut(df$POBLACION_2025, right=F, breaks=c(0,1000,5000,10000,20000,Inf),
                    labels=c("[ 0 - 1000 >",
                             "[ 1000 - 5000 >",
                             "[ 5000 - 10000 >",
                             "[ 10000 - 20000 >",
                             "[ 20000 - ∞ >"))

colores <- c('#edf8fb','#b3cde3','#8c96c6','#8856a7','#810f7c')

library(sf)
library(ggplot2)
ggplot(df, aes(geometry=geometry)) +
  scale_fill_manual(values=colores)+
  geom_sf(aes(fill=Categoría))

Use the natural region information on a district level map.

library(mapsPERU)
df <- map_DIST

df$REGION_NATURAL <- ordered(df$REGION_NATURAL, levels=c("Costa","Sierra","Selva"))

colores <- c('#F1C40F','#D35400','#229954')

library(sf)
library(ggplot2)
ggplot(df, aes(geometry=geometry)) +
  scale_fill_manual(values=colores) +
  geom_sf(aes(fill=REGION_NATURAL)) +
  labs(fill='Región natural')