Workshops for Ukraine
Photo by Mario Gogh on Unsplash
[1] "#28A87D" "#2FA178" "#379B72" "#3E956D" "#468E69" "#4D8864" "#55825F" "#5C7B59" "#647555" "#6B6F50" "#73694A" "#7A6245" "#825C41" "#89563C" "#914F37"
[16] "#984932" "#A0432C" "#A83D28" "#A03E2F" "#983F37" "#91403E" "#894246" "#82434D" "#7A4455" "#73465C" "#6B4764" "#64486B" "#5C4973" "#554B7A" "#4D4C82"
[31] "#464D89" "#3E4F91" "#375098" "#2F51A0" "#2853A8"
[1] "#28A87D" "#2EA379" "#349E75" "#3A9971" "#41946E" "#478F6A" "#4D8A66" "#548563" "#5A805F" "#607B5B" "#677658" "#6D7154" "#736C50" "#7A674D" "#806249"
[16] "#865D45" "#8D5842" "#93543E" "#994F3A" "#A04A37" "#A64533" "#AC402F" "#B33B2C" "#B93628" "#BF3124" "#C62C21" "#CC271D" "#D22219" "#D91D16" "#DF1812"
[31] "#E5130E" "#EC0E0B" "#F20907" "#F80403" "#FF0000"
The color adjustment can be calculated in three different color spaces.
If
space = "HCL"
, the colors are transformed to HCL, (polarLUV), the luminance component L is adjusted, and then the colors are transformed back to a hexadecimal RGB string.If
space = "HLS"
, the colors are transformed to HLS, the lightness component L is adjusted, and then the color is transformed back to a hexadecimal RGB string.If
space = "combined"
, the colors are first adjusted in both the HCL and HLS spaces. Then, the adjusted HLS colors are converted into HCL, and then the chroma components of the adjusted HLS colors are copied to the adjusted HCL colors. Thus, in effect, the combined model adjusts luminance in HCL space but chroma in HLS space.
{dichromat}
– for dichromats *{fishualize}
– based on teleost fishes{ggsci}
– based on scientific journal and Sci-Fi movies{ggthemes}
– based on popular news rooms and software{ghibli}
– based on Studio Ghibli movies{MetBrewer}
– inspired by the Metropolitan Museum of Art{nord}
– collection of northern inspired palettes{pals}
– comprehensive collection of recommended palettes *{Redmonder}
– inspired by Microsoft products *{wesanderson}
– based on movies by Wes Anderson *library(ggplot2)
library(dplyr)
library(prismatic)
theme_set(theme_minimal(base_family = "Asap Condensed", base_size = 15, base_line_size = .5))
theme_update(
panel.grid.minor = element_blank(),
plot.title = element_text(
face = "bold", size = rel(1.5), margin = margin(b = 15)
),
plot.title.position = "plot",
plot.caption = element_text(
color = "grey45", size = rel(.7), hjust = 0, margin = margin(t = 15)
),
plot.caption.position = "plot"
)
Rows: 159
Columns: 11
$ sovereignt <chr> "Cuba", "Denmark", "Saudi Arabia", "Yemen", "Italy", "Comoros", "Gabon", "Norway", "Kyrgyzstan", "Madagascar", "Libya", "Bahrain", "Ven…
$ iso_a3 <chr> "CUB", "DNK", "SAU", "YEM", "ITA", "COM", "GAB", "NOR", "KGZ", "MDG", "LBY", "BHR", "VEN", "TGO", "KOR", "TKM", "IRL", "KEN", "SVN", "S…
$ type <chr> "Sovereignty", "Country", "Sovereign country", "Sovereign country", "Sovereign country", NA, "Sovereign country", NA, "Sovereign countr…
$ continent <chr> "North America", "Europe", "Asia", "Asia", "Europe", NA, "Africa", NA, "Asia", "Africa", "Africa", NA, "South America", "Africa", "Asia…
$ region_un <chr> "Americas", "Europe", "Asia", "Asia", "Europe", NA, "Africa", NA, "Asia", "Africa", "Africa", NA, "Americas", "Africa", "Asia", "Asia",…
$ subregion <chr> "Caribbean", "Northern Europe", "Western Asia", "Western Asia", "Southern Europe", NA, "Middle Africa", NA, "Central Asia", "Eastern Af…
$ gdp_per_capita <dbl> 8000, 44836, 51397, 2506, 33419, 1702, 18413, 82814, 4879, 1381, 8096, 41078, 15219, 1400, 36103, 23813, 56597, 3169, 26908, 44659, 585…
$ urban_pop <dbl> 76.930, 87.642, 83.401, 35.394, 69.855, 28.619, 88.559, 81.485, 35.944, 35.856, 79.540, 89.090, 88.165, 40.628, 81.562, 50.728, 62.737,…
$ pop_est <dbl> 11333483, 5818553, 34268528, 29161922, 60297396, NA, 2172579, NA, 6456900, 26969307, 6777452, NA, 28515829, 8082366, 51709098, 5942089,…
$ economy <chr> "5. Emerging region: G20", "2. Developed region: nonG7", "2. Developed region: nonG7", "7. Least developed region", "1. Developed regio…
$ income_grp <chr> "3. Upper middle income", "1. High income: OECD", "2. High income: nonOECD", "4. Lower middle income", "1. High income: OECD", NA, "3. …
#remotes::install_github("wmgeolab/rgeoboundaries")
library(tidyverse)
sf_world_ne <- rnaturalearth::ne_countries(scale = 110, returnclass = "sf")
sf_world_correct <- rgeoboundaries::gb_adm0()
owid_data <- readr::read_csv("data/owid-urbanization-vs-gdp.csv")
## via https://ourworldindata.org/urbanization
sf_world <- sf_world_correct %>%
left_join(sf::st_drop_geometry(sf_world_ne), by = c("shapeISO" = "iso_a3")) %>%
left_join(
owid_data %>%
janitor::clean_names() %>%
rename(urban_pop = "urban_population_percent_long_run_to_2016_owid") %>%
filter(year == 2016),
by = c("shapeISO" = "code")
) %>%
dplyr::select(
sovereignt = shapeName, iso_a3 = shapeISO, type, continent = continent.x,
region_un, subregion, gdp_per_capita, urban_pop, pop_est, economy, income_grp
) %>%
mutate(pop_est = as.numeric(pop_est)) %>%
filter(!sovereignt == "Antarctica")
df_world <- sf_world %>%
sf::st_drop_geometry() %>%
filter(!is.na(gdp_per_capita), !is.na(urban_pop))
readr::write_rds(sf_world, "data/urban-gdp-pop-sf.rds")
readr::write_csv(df_world, "data/urban-gdp-pop.csv")
p <-
ggplot(data = df_world,
mapping = aes(x = gdp_per_capita, y = urban_pop, size = pop_est)) +
coord_cartesian(expand = FALSE, clip = "off") +
scale_x_log10(labels = scales::label_dollar()) +
scale_y_continuous(labels = function(y) paste0(y, "%"), limits = c(0, 100)) +
scale_size_area(max_size = 15, breaks = c(10, 100, 500, 1000) * 10^6,
labels = scales::label_number(scale = 1/10^6, suffix = "M")) +
labs(x = NULL, y = NULL,
fill = "Continent:", size = "Population:",
title = "Urban population vs. GDP per capita, 2016",
caption = "Sources: ourworldindata.org/urbanization; NaturalEarth; geoBoundaries API | x-axis on log scale") +
guides(fill = guide_legend(override.aes = list(size = 3)),
size = guide_legend(override.aes = list(color = "black", fill = "grey85")))
p + geom_point(aes(fill = region_un), shape = 21, alpha = .5, stroke = .7)
scale_color|fill_manual()
after_scale()
b <- ggplot(
data = df_world,
mapping = aes(
x = gdp_per_capita,
y = forcats::fct_reorder(
region_un, -gdp_per_capita
)
)
) +
scale_x_continuous(
labels = scales::dollar_format()
) +
guides(color = "none") +
labs(x = "GDP per capita", y = NULL) +
theme(panel.grid.major.y = element_blank())
b +
geom_boxplot(
aes(color = region_un),
width = .7
) +
scale_color_manual(values = pal)
p +
geom_point(
aes(fill = region_un != "Africa"),
shape = 21, alpha = .5, stroke = .7
) +
scale_fill_manual(
values = c("#D00000", "grey80")
) +
guides(fill = "none") +
labs(subtitle = "of <b style='color:#D00000;'>African</b> and <b style='color:grey70;'>non-African</b> countries") +
theme(
plot.subtitle = ggtext::element_markdown(
margin = margin(t = -15, b = 20),
size = rel(1.3)
)
)
p +
geom_point(
aes(fill = region_un != "Africa",
color = after_scale(fill)),
shape = 21, alpha = .5, stroke = .7
) +
scale_fill_manual(
values = c("#D00000", "grey80")
) +
labs(subtitle = "of <b style='color:#D00000;'>African</b> and <b style='color:grey70;'>non-African</b> countries") +
guides(fill = "none") +
theme(
plot.subtitle = ggtext::element_markdown(
margin = margin(t = -15, b = 20),
size = rel(1.3)
)
)
pal_hl <- c("#7754BF", "#28A74D", "grey80")
p +
geom_point(
data = df_world,
aes(fill = cont_lumped,
color = after_scale(clr_darken(fill, .3))),
shape = 21, alpha = .5, stroke = .7
) +
scale_fill_manual(values = pal_hl) +
labs(subtitle = "of <b style='color:#7754BF;'>Asian</b> and <b style='color:#28A74D;'>European</b> countries compared to all <span style='color:grey60;'>other countries</span>") +
guides(fill = "none") +
theme(
plot.subtitle = ggtext::element_markdown(
margin = margin(t = -15, b = 20),
size = rel(1.3)
)
)
m <-
ggplot(data = sf_world) +
geom_sf(aes(fill = urban_pop), color = "white", lwd = .3) +
coord_sf(crs = "+proj=eqearth") +
labs(
title = "Share of people living in urban areas, 2016",
caption = "Sources: ourworldindata.org/urbanization; NaturalEarth; geoBoundaries API",
fill = NULL
) +
theme(
axis.text = element_blank(),
panel.grid.major = element_blank(),
legend.key.width = unit(2.5, "lines"),
legend.key.height = unit(.6, "lines"),
legend.position = "bottom"
)
m
pt <- p +
geom_point(
data = df_world,
aes(fill = cont_lumped,
color = after_scale(clr_darken(fill, .3))),
shape = 21, alpha = .5, stroke = .7
) +
scale_fill_manual(values = pal_hl)
mt <- m + scale_fill_gradient2(
low = "#7754BF", mid = "grey90", high = "#208462", midpoint = 50,
na.value = "grey85", labels = function(x) paste0(x, "%")
)
pal_seq_1 <- viridis::cividis(n = 7)
pal_seq_2 <- scico::scico(palette = "bamako", n = 7)
pal_div_1 <- RColorBrewer::brewer.pal(name = "RdYlBu", n = 7)
pal_div_2 <- MetBrewer::met.brewer(name = "Hiroshige", n = 7)
pal_cat_1 <- rcartocolor::carto_pal(name = "Prism", n = 7)
pal_cat_2 <- ggthemes::excel_pal()(7)
Cédric Scherer // Workshops for Ukraine // Jan 26, 2022