library(ggiraph)
library(ggplot2)
library(showtext)
library(ggtext)
library(glue)
font_add_google(name = "Tinos", family = "tinos")
showtext_auto()
showtext_opts(dpi = 300)
arg <- sf::st_read("vector/arg_simp.gpkg", quiet = TRUE)
p <- ggplot() +
geom_sf_interactive(
data = arg,
aes(
tooltip = Provincia,
data_id = Provincia,
onclick = sprintf(
"window.open(\"http://es.wikipedia.org/wiki/%s\")",
paste0("Provincia_de_", gsub(" ", "_", Provincia))
),
),
fill = "#75aee0",
color = "#e5e5e5",
linewidth = 15
) +
annotate(
geom = "richtext",
x = I(c(-1.7, -1.7, -1.7)),
y = I(c(.9, .8, .1)),
hjust = 0,
label = c(
"República <b style='color: #75aee0;'>Argentina</b>",
"Click en cualquier provincia para<br>visitar su página en <b style='color: #f6b40e'>Wikipedia</b>",
"**Víctor Gauto | @vhgauto**"
),
fill = c(NA, NA, "#75aee0"),
label.color = NA,
label.r = unit(0, "line"),
label.padding = unit(20, "lines"),
size = c(800, 500, 300),
color = c("black", "black", "black"),
family = "tinos"
) +
coord_sf(clip = "off") +
theme_void(base_family = "tinos") +
theme_sub_plot(
margin = margin(l = 25000),
title = element_text(hjust = 0),
subtitle = ggtext::element_markdown()
)
girafe(
ggobj = p,
width_svg = 1500,
height_svg = 600,
bg = "#e5e5e5",
options = list(
opts_tooltip(
css = glue(
"background-color:white;color:black;padding:5px;",
"font-weight:bold;font-size:15pt;border-radius:0px;",
"border-style:solid;border-color:black;border-width:1px;",
"font-family:Lato;"
),
opacity = 1
),
opts_hover(
css = girafe_css(
css = "",
area = glue("fill:#f6b40e;")
)
),
opts_hover_inv(css = "opacity:1"),
opts_toolbar(saveaspng = FALSE)
)
)