Code
library(here)
library(tidyverse)
# library(targets)
library(sf)
library(gt)
library(kableExtra)
# library(lubridate)
clrs_light <- MetBrewer::met.brewer("Tiepolo") %>% colorspace::lighten(0.8)
# Generated via random.org
set.seed(2385)In many cases
Here’s an overview of these variables:
starwars2 <- starwars |>
select(1, 4,5,8,10,11,12) |>
sample_n(10) |>
glimpse()
## Rows: 10
## Columns: 7
## $ name <chr> "Wat Tambor", "BB8", "Jocasta Nu", "Owen Lars", "Tion Medon", "Poggle the Lesser", "Leia Organa", "…
## $ hair_color <chr> "none", "none", "white", "brown, grey", "none", "none", "brown", "black", "none", "brown"
## $ skin_color <chr> "green, grey", "none", "fair", "light", "grey", "green", "light", "brown", "mottled green", "fair"
## $ sex <chr> "male", "none", "female", "male", "male", "male", "female", "male", "male", "male"
## $ homeworld <chr> "Skako", NA, "Coruscant", "Tatooine", "Utapau", "Geonosis", "Alderaan", "Iridonia", "Cato Neimoidia…
## $ species <chr> "Skakoan", "Droid", "Human", "Human", "Pau'an", "Geonosian", "Human", "Zabrak", "Neimodian", "Human"
## $ films <list> "Attack of the Clones", "The Force Awakens", "Attack of the Clones", <"A New Hope", "Attack of the …And here’s an extract of the data from June 11, 2020, the day that Argentina filed a derogation notice:
starwars2 %>%
gt() %>%
cols_width(name ~ px(60),
homeworld ~ px(100),
films ~ px(150),
) %>%
data_color(columns = contains("color"),
fn = scales::col_factor(c(clrs_light[1], clrs_light[8]),
domain = c(FALSE, TRUE))) %>%
opt_interactive(use_compact_mode = TRUE, use_highlight = TRUE)
## Warning: Some values were outside the color scale and will be treated as NA
## Some values were outside the color scale and will be treated as NA---
title: "Data prep useful functions"
format:
html:
code-fold: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
fig.align = "center",
fig.retina = 3,
fig.width = 6,
fig.height = (6 * 0.618),
out.width = "80%",
collapse = TRUE,
dev = "png",
dev.args = list(type = "cairo-png")
)
options(
digits = 3,
width = 120,
dplyr.summarise.inform = FALSE,
knitr.kable.NA = ""
)
```
```{r load-libraries, warning=FALSE, message=FALSE}
library(here)
library(tidyverse)
# library(targets)
library(sf)
library(gt)
library(kableExtra)
# library(lubridate)
clrs_light <- MetBrewer::met.brewer("Tiepolo") %>% colorspace::lighten(0.8)
# Generated via random.org
set.seed(2385)
```
```{r load-data, warning=FALSE, message=FALSE}
starwars <- readRDS(here("data","input_data","starwars.Rds"))
```
:::{.callout-note}
In many cases
:::
Here's an overview of these variables:
```{r glimpse}
#| code-fold: false
starwars2 <- starwars |>
select(1, 4,5,8,10,11,12) |>
sample_n(10) |>
glimpse()
```
And here's an extract of the data from June 11, 2020, the day that Argentina filed a derogation notice:
```{r show}
#| column: page-right
starwars2 %>%
gt() %>%
cols_width(name ~ px(60),
homeworld ~ px(100),
films ~ px(150),
) %>%
data_color(columns = contains("color"),
fn = scales::col_factor(c(clrs_light[1], clrs_light[8]),
domain = c(FALSE, TRUE))) %>%
opt_interactive(use_compact_mode = TRUE, use_highlight = TRUE)
```
<!-- And here's a map of all the countries that derogated between January 2020 and June 2021: -->
<!-- ```{r derogations-map, fig.width=6.5, fig.height=3.5} -->
<!-- ggplot() + -->
<!-- geom_sf(data = derogation_map_data, aes(fill = derogations_1plus), -->
<!-- linewidth = 0.1, color = "white") + -->
<!-- coord_sf(crs = st_crs("+proj=robin"), datum = NA) + -->
<!-- scale_fill_binned(low = colorspace::lighten(clrs[1], amount = 0.8), -->
<!-- high = clrs[1], na.value = "grey85", -->
<!-- breaks = c(1, 5, 10, 15, 20), -->
<!-- limits = c(1, 20), -->
<!-- name = "Derogations filed: ", -->
<!-- guide = guide_colorsteps(barwidth = 7, barheight = 0.4, -->
<!-- title.vjust = 1)) + -->
<!-- theme_pandem() + -->
<!-- theme(panel.border = element_blank(), -->
<!-- legend.title = element_text(face = "bold"), -->
<!-- legend.justification = "center") -->
<!-- ``` -->
```{r save}
saveRDS(starwars2, here("data","output_data","starwars2.Rds"))
```