Paquetes de R
x <- c("sf","ggplot2","ggmap","broom","rgdal","tidyverse")
lapply(x, library, character.only = TRUE) # carga los paquetes requeridos
Mapa de la zona del contexto https://www.keene.edu/campus/maps/tool/
rutamc<-"D:/Documents/Claudia/Midropbox/Investigacion y escritos/mapasnacionales"
rutacam<-"D:/Documents/Claudia/Midropbox/Investigacion y escritos/mapasnacionales/"
ylim=c(25.47, 25.67)
xlim=c(-103.30, -103.52)
tormun <- readOGR(rutamc,"torageb", use_iconv = TRUE, encoding = "latin1")
## OGR data source with driver: ESRI Shapefile
## Source: "D:\Documents\Claudia\Midropbox\Investigacion y escritos\mapasnacionales", layer: "torageb"
## with 332 features
## It has 5 fields
# Para poder graficar con ggplot se convierte en una tabla (dataframe) (paquete broom)
tormun$id <- rownames(tormun@data)
tormun_df <- tidy(tormun, region = "id")
# Se agrega un identificador al shapefile que corresponderá al número de renglón
# Se reunen los dos archivos a partir del id
tormun_df <- left_join(tormun_df,tormun@data,by = "id")
Mapa sin y con fondo de la capa de AGEBs
mapgde = ggplot() +
geom_path(data = tormun_df,aes(x = long, y = lat, group = group),color="steelblue") +
theme_void()
mapgde
height <- max(tormun_df$lat) - min(tormun_df$lat)
width <- max(tormun_df$long) - min(tormun_df$long)
tor_borders <- c(bottom = min(tormun_df$lat) - 0.1 * height,
top = max(tormun_df$lat) + 0.1 * height,
left = min(tormun_df$long) - 0.1 * width,
right = max(tormun_df$long) + 0.1 * width)
map <- get_stamenmap(tor_borders, zoom = 12, maptype = "terrain")
ggmap(map)+
geom_path(data = tormun_df,aes(x = long, y = lat, group = group),color="steelblue") +
theme_void()
Mapas con fondo capa de ejes viales y recorte de polÃgono
tormunc <- readOGR(rutamc,"muntor", use_iconv = TRUE, encoding = "latin1")
limitesbox<-read.csv(paste0(rutacam,"limites.txt"),header=TRUE, sep=",",encoding="latin")
names(limitesbox)<-c("long","lat")
#Crear el polÃgono
p = Polygon(limitesbox)
ps = Polygons(list(p),1)
sps = SpatialPolygons(list(ps))
sps_bb<-st_as_sfc(sps)
#proj4string(sps)
#proj4string(tormun)
sp::proj4string(sps) <- CRS("+proj=longlat +datum=WGS84 +no_defs")
muninsps <- tormunc[sps, ]
ggmap(map)+
geom_path(data = muninsps,aes(x = long, y = lat, group = group),color="steelblue") +
theme_void()
via_paletacol <- c("Calle" = "green",
"Boulevard" ="red",
"Avenida" = "blue",
"Privada" = "grey",
"Circuito" = "orange",
"Cerrada" = "purple")
muninsps_df <- tidy(muninsps, region = "id")
# Se agrega un identificador al shapefile que corresponderá al número de renglón
muninsps$id <- rownames(muninsps@data)
# Se reunen los dos archivos a partir del id
muninsps_df <- left_join(muninsps_df,muninsps@data,by = "id")
ggmap(map)+
geom_path(data = muninsps_df, aes(x = long, y = lat, group = group, color=TIPOVIAL)) +scale_colour_manual(values =via_paletacol) +
theme(axis.text = element_blank(), axis.ticks = element_blank())+theme_void()
height <- max(muninsps_df$lat) - min(muninsps_df$lat)
width <- max(muninsps_df$long) - min(muninsps_df$long)
tor_borders <- c(bottom = min(muninsps_df$lat) - 0.5 * height,
top = max(muninsps_df$lat) + 0.5 * height,
left = min(muninsps_df$long) - 0.5 * width,
right = max(muninsps_df$long) + 0.5 * width)
map <- get_stamenmap(tor_borders, zoom = 12, maptype = "toner")
ggmap(map)+
geom_path(data = muninsps_df, aes(x = long, y = lat, group = group, color=TIPOVIAL)) +scale_colour_manual(values =via_paletacol) +
theme(axis.text = element_blank(), axis.ticks = element_blank())+theme_void()
ggsave("fondo_map.png", width = 1300, height = 1300, units = "mm", dpi = "retina",limitsize = FALSE)