p1 <- suppressWarnings(
ne_countries(scale = "large", returnclass = "sf") %>%
left_join(
porcen_journal %>%
filter(!country %in% c("Total")) %>%
mutate(
country = trimws(country),
country_std = case_when(
country %in% c("United States", "USA") ~ "United States of America",
TRUE ~ countrycode(country, origin = "country.name", destination = "country.name")
),
country_std = coalesce(country_std, country),
color_point = case_when( n <= 20 ~ "#91A1AF",
n <= 50 ~ "#21BCFF",
n <= 100 ~ "#F5276C",
n <= 200 ~ "#2C0995",
n <= 300 ~ "#27F5B0",
n <= 450 ~ "#009E3F",
n <= 600 ~ "#2e86c1",
n <= 800 ~ "#1b4f72",
n <= 1000 ~ "#884ea0",
n <= 1250 ~ "#a569bd",
n <= 1500 ~ "#af7ac5",
n <= 1750 ~ "#d98880",
n <= 2500 ~ "#8965F6",
n <= 3500 ~"#729509",
TRUE ~ "darkblue"
)
),
by = c("name" = "country_std")
) %>%
filter(!is.na(geometry)) %>%
mutate(point_geom = st_point_on_surface(geometry),
tooltip_text = paste0("<strong>", name, "</strong><br/>Revistas: ", n)) %>%
ggplot() +
geom_sf(fill = "gray90", color = "white", size = 0.1) +
geom_point_interactive(
aes(
geometry = point_geom,
size = n,
color = color_point,
tooltip = tooltip_text,
data_id = name
),
stat = "sf_coordinates",
alpha = 0.7
) +
scale_size_continuous(range = c(2, 10), guide = "none") +
scale_color_identity(
name = "Rangos de n",
guide = "legend",
breaks = c("#91A1AF", "#21BCFF", "#F5276C", "#2C0995",
"#27F5B0", "#009E3F", "#2e86c1", "#1b4f72",
"#884ea0", "#a569bd", "#af7ac5", "#d98880",
"#8965F6", "#729509", "darkblue"),
labels = c("≤ 20", "21–50", "51–100", "101–200",
"201–300", "301–450", "451–600", "601–800",
"801–1000", "1001–1250", "1251–1500", "1501–1750",
"1751–2500", "2501–3500", "> 3500")
)
+
labs(
title = "Distribución de revistas por país",
x = NULL,
y = NULL,
caption = add_caption()
) +
theme_minimal() +
theme(plot.title = element_text(size = 18, face = "bold"),
legend.title = element_text(size = 14, face = "bold"),
legend.text = element_text(size = 12),
legend.position = "bottom"))
girafe(
ggobj = p1,
options = list(
opts_hover(css = "fill-opacity:1;stroke:black;stroke-width:1pt;"),
opts_tooltip(css = "background-color:white;color:black;padding:5px;border-radius:5px;font-family:sans-serif;"),
opts_toolbar(saveaspng = TRUE)
),
width_svg = 10,
height_svg = 7
)