R/shapefile.R

# SHAPEFILE MAP VENEZUELA

library("sf");
library("mapview");
library("utf8");
library("ggplot2");
library("ggrepel");

# Cargar datos en fotmato .sph utilizando la función st_read()

sf <- st_read("Estados_Venezuela.shp")
sf <- st_read("Linea_de_Costa_Venezuela.shp")

setwd("C:/Users/Freddy/Desktop/github")

# Ubicaciones de cada capital

labs <- data.frame(
  Longitud = c(-71.1389,-71.6295,-70.2074,-68.0076,-66.8791,-67.6754,-69.4328,-63.6004,-64.7000,-63.3333,-72.2918,-67.4695,-69.7747,-67.6248,-63.8998,-70.4741,-69.7075,-68.6178,-64.2419,-67.3803,-66.9431,-68.7595,-62.0825,-67.0768),
  Latitud  = c(8.6149,10.6417,8.6226,10.1620,10.4880,10.2673,10.0620,8.0749,10.1333,9.7500,7.7619,7.8726,9.0429,5.6469,11.0351,9.3709,11.4053,9.6610,10.4171,9.9004,10.5852,10.3403,9.0523,10.3483),
  Ciudad = c("Mérida",
             "Maracaibo",
             "Barinas",
             "Valencia",
             "CARACAS\n Capital del país",
             "Maracay",         
             "Barquisimeto",
             "Ciudad Bolívar",
             "Barcelona",
             "Maturín",
             "San Cristobal",
             "San Fernando",
             "Guanare",
             "Puerto Ayacucho",
             "La Asunción",          
             "Trujillo",
             "Coro",
             "San Carlos",
             "Cumaná",
             "San Juan de Los Morros",
             "La Guaira",
             "San Felipe",
             "Tucupita",
             "Los Teques"),
  stringsAsFactors = FALSE
)

es=labs$Ciudad
col=colors()[27:51]


# Gráfico utilizando la libreria "ggplot2"

ggplot() + 
  geom_sf(data = sf, size = 0.1, bg=col) + 
  ggtitle("CAPITALES DE VENEZUELA", subtitle = "Shapefile Map") + 
  geom_point(data=labs, aes(x = Longitud, y = Latitud), color="red", size = 3, stroke=1,fill = "white",shape = 21) + 
  geom_label_repel(data=labs, aes(x=Longitud, y=Latitud, label=Ciudad), color = "blue", size = 3, vjust=-1) + theme(legend.position = "bottom") + 
  coord_sf() 
freddyvillabona/Shapefile-Map-GIS documentation built on June 29, 2019, 12:13 a.m.