I have this code that plots the map of Brazil, however I need the map to show the states limits, how do I do this?
world <- ne_countries(scale = "medium", returnclass = "sf") class(world)
sites <- data.frame(Longitude = c(-55.8683, -42.9999, -39.0676, -35.1046, -39.7717, -42.4000, -48.9946, -41.0526, -53.0000), Latitude = c(-1.7670, -5.0951, -13.3724, -8.7500, -18.7747, -5.0892, -12.4332, -21.6488, 4.0040))
row.names(sites) <- c("1 Oriximiná-PA", "2-7 Timon-MA", "3 Valença-BA", "4 Tamandaré-PE", "5 Guriri-ES", "6 Teresina-PI", "8-9 Brasil", "10 São João da Bara-RJ", "11 Guiana Francesa") sites
sites$Cidades <- c("Oriximiná - PA", "Timon - MA", "Valença - BA", "Tamandaré - PE", "Guriri - ES", "Teresina - PI", "Brasil - BR", "São João da Bara - RJ", "Guiana Francesa - GF") sites
ggplot(data = world) geom_sf() geom_point(data = sites, aes(x = Longitude, y = Latitude, shape= Cidades), size = 3) scale_shape_manual("Cidades", values = c(17, 15, 13, 7, 4, 0, 6, 19, 1)) coord_sf(xlim = c(-60, -29), ylim = c(-23, 6), expand = FALSE) theme(text = element_text(size=10), plot.title = element_text(size=12, hjust=0.5), axis.text.x = element_text(size = 10, angle=0, hjust=1), axis.text.y = element_text(size = 10, angle=0, vjust=1), axis.title.x = element_text(size = 9, angle=0), axis.title.y = element_text(size = 9, angle=90))
CodePudding user response:
library(tidyverse)
library(ggmap)
#> Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
#> Please cite ggmap if you use it! See citation("ggmap") for details.
library(raster)
#> Loading required package: sp
#>
#> Attaching package: 'raster'
#> The following object is masked from 'package:dplyr':
#>
#> select
#> The following object is masked from 'package:tidyr':
#>
#> extract
sites <- data.frame(
Longitude = c(-55.8683, -42.9999, -39.0676, -35.1046, -39.7717, -42.4000, -48.9946, -41.0526, -53.0000),
Latitude = c(-1.7670, -5.0951, -13.3724, -8.7500, -18.7747, -5.0892, -12.4332, -21.6488, 4.0040)
)
sites
#> Longitude Latitude
#> 1 -55.8683 -1.7670
#> 2 -42.9999 -5.0951
#> 3 -39.0676 -13.3724
#> 4 -35.1046 -8.7500
#> 5 -39.7717 -18.7747
#> 6 -42.4000 -5.0892
#> 7 -48.9946 -12.4332
#> 8 -41.0526 -21.6488
#> 9 -53.0000 4.0040
# Coarse map of neighbor countries (level 0)
other_countries <-
c("Peru", "Bolivia", "French Guiana", "Suriname", "Guyana",
"Venezuela", "Colombia", "Ecuador", "Peru", "Bolivia",
"Paraguay", "Uruguay", "Argentina"
) %>%
map(~ getData(country = .x, level = 0)) %>%
reduce(rbind)
# Detailed map of Brazil (level 1)
getData(country = "Brazil", level = 1) %>%
ggplot(aes(x = long, y = lat))
geom_polygon(
mapping = aes(group = group),
color = "black",
fill = "grey"
)
geom_polygon(
data = other_countries,
mapping = aes(group = group),
colour = "black", fill = "transparent"
)
geom_point(data = sites, mapping = aes(x = Longitude, y = Latitude), color = "red")
coord_fixed()
#> Regions defined for each Polygons
#> Regions defined for each Polygons
Created on 2021-09-29 by the reprex package (v2.0.1)