Hola! Aguien sabe cómo puedo colorear algunos países dentro del mapa mundi?
La idea es que se visualice el mapamundi y en un color diferente algunos países como "Paraguay" , "Chile", "Perú", "México" .
Utilicé este scripts:
library(mapdata)
library(ggplot2)
library(maps)
library(ggrepel)
library(dplyr)
mapa_mundo <- map_data("world")
mapa_mundo %>%
ggplot() +
geom_polygon(aes( x= long, y = lat, group = group),
fill = "grey80",
color = "white") +
theme_minimal() +
theme(
axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
panel.background = element_rect(colour= "black", size= 1)) +
ggtitle( "Mapa Mundi")
DavoWW
2
Hi @Gissella,
Bienvenido al Foro de la comunidad de RStudio.
Prueba este código:
library(mapdata)
#> Loading required package: maps
library(ggplot2)
library(maps)
library(ggrepel)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
mapa_mundo <- map_data("world")
head(mapa_mundo)
#> long lat group order region subregion
#> 1 -69.89912 12.45200 1 1 Aruba <NA>
#> 2 -69.89571 12.42300 1 2 Aruba <NA>
#> 3 -69.94219 12.43853 1 3 Aruba <NA>
#> 4 -70.00415 12.50049 1 4 Aruba <NA>
#> 5 -70.06612 12.54697 1 5 Aruba <NA>
#> 6 -70.05088 12.59707 1 6 Aruba <NA>
#levels(factor(mapa_mundo$region))
my_labels <- c("Paraguay", "Chile", "Perú", "México")
my_countries <- c("Paraguay", "Chile", "Peru", "Mexico")
mapa_mundo %>%
filter(region %in% my_countries) -> map2
mapa_mundo %>%
ggplot() +
geom_polygon(aes(x=long, y=lat, group=group), fill="grey90", colour="grey90") +
theme_minimal() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
panel.background = element_rect(colour= "black", size= 1)) +
geom_polygon(data=map2, aes(x=long, y=lat, group=group, fill=region)) +
theme(legend.position = 'none') +
ggtitle( "Mapa Mundi")

Created on 2021-07-25 by the reprex package (v2.0.0)
1 Like
system
Closed
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.