::include_graphics('plots/day19_dcc_22.gif') knitr
Day 19
R
Data Viz
ggplot2
Data analysis
Day 19 from #30dataChartChallenge
Code
::shelf(
librarian
tidyverse
, gapminder
, sf
, maps
)
<-
pover read_csv(here::here("data", "owd", "extreme-poverty.csv")) |>
rename(
country = 1
year = 3
, pover = 4
, |>
) mutate(
country = ifelse(str_detect(country, "Argentina"), "Argentina", country)
)
<-
am_cnt |>
pover left_join(gapminder, by = "country") |>
filter(
== "Americas"
continent |>
) distinct(country) |>
pull()
<-
pover_latam |>
pover filter(country %in% am_cnt) |>
# distinct(country) |>
# pull()
select(!Code)
<-
latim map_data("world") |> as_tibble() |> rename(country = region) |>
filter(country %in% am_cnt) |>
right_join(pover_latam) |>
filter(country != "Canada")
<- colorRampPalette(c("#ead9d5", '#560100')) t2
<- function(anio){
plot_fill ::cli_process_start("year {.val {anio}}")
cli<- latim |>
p filter(year == anio) |>
ggplot() +
aes(long, lat, group = paste(country, group), fill = pover) +
geom_polygon(color = "gray90", size = .23) +
coord_fixed() +
scale_fill_gradientn(colors = t2(2)) +
labs(
title = glue::glue("Latinoamérica - Pobreza extrema", "\n{anio}")
caption = "#30DayChartChallenge | Day 19: Global Change\nData: OWID | @JhonKevinFlore1"
, fill = "%"
, +
) guides(
fill = guide_colorbar(
direction = "horizontal"
title.position = "top"
, title.hjust = .5
, label.hjust = .5
, label.position = "bottom"
, keywidth = .2
, keyheight = .2
,
)+
) theme_void() +
# hrbrthemes::theme_ft_rc(grid = FALSE, axis_text_size = 0) +
theme(
legend.position = c(.3, .35)
legend.text = element_text()
, plot.title = element_text(hjus = .5, face = "bold")
, plot.subtitle = element_text( hjust = .5)
, plot.caption = element_text(hjust = 1, vjust = .5)
, plot.caption.position = 'panel'
,
)plot(p)
::cli_process_done()
cli }
plot_fill("1989")
ggsave(here::here("plots", "day19.png"))
::saveGIF({
animation::walk(unique(pover_latam$year), plot_fill)
purrrmovie.name = here::here('plots/day19_dcc_22.gif')
} , interval = .5
, ani.width = 1385
, ani.height = 1500
, ani.res = 300
, )