Skip to content

Instantly share code, notes, and snippets.

View cararthompson's full-sized avatar

Cara Thompson cararthompson

View GitHub Profile
@cararthompson
cararthompson / gist:b4f1c8a2ec5034c512c181ee5d778a8f
Created September 20, 2024 09:40
Parameterised legend order
for(n in 35:55) {
demo_data <- palmerpenguins::penguins |>
sample_n(n) |>
filter(!is.na(sex)) |>
group_by(sex, species) |>
count() |>
ungroup() |>
arrange(n) |>
@cararthompson
cararthompson / gist:68aeab14eb9a08245f6c2907697f7685
Created June 25, 2024 09:41
Where are all the women - dataviz
representation <- dplyr::tibble(party = c("Labour",
"Green",
"Liberal Democrats",
"Trade Unionist and Socialist Coalition",
"Conservative",
"Independent",
"Reform UK",
"General Population"),
women = c(41, 41, 33, 33, 29, 28, 22, 51)) |>
# Keep the parties in current order (proportion)
# Cheesy Proportions
library(tidyverse)
# Dataset - Source, BBC News
cheese_proportions <- tibble(
name = c("Profit", "Processor", "Retailer", "Farming"),
amount = c(3.5, 42.5, 56, 148)
) |>
mutate(proportion = amount / sum(amount) * 100) %>%
arrange(proportion) %>%
@cararthompson
cararthompson / gist:d539190ee62a2bd102039c045125af0b
Last active February 9, 2023 12:37
Turning #rstats tweetorials into quarto blog posts
library(tidyverse)
# Retrieve data on all tweets ----
# From documentation: Set n = Inf to download as many results as possible.
my_tweets <- rtweet:: get_timeline(user = "myusername",
n = Inf, retryonratelimit = TRUE)
# Pick only the ones which are the starting points (we'll retrieve all the ones that are replies to it in the next step) ----
thread_starts <- my_tweets |>
@cararthompson
cararthompson / gist:6832c1308af584b403c5541051105ddf
Created October 28, 2022 16:20
Basic plot example - Level up your plots
library(palmerpenguins)
library(tidyverse)
ggplot(penguins,
aes(x = bill_depth_mm,
y = bill_length_mm,
colour = species)) +
geom_point() +
labs(title = "Perfectly Proportional Penguins",
subtitle = "Look at them go!")
library(tidyverse)
library(sf)
obtn_year <- 2022
obtn_boundaries_oregon_census_tracts <- read_rds("https://github.com/rfortherestofus/obtn/raw/data-2022/inst/obtn_boundaries_oregon_census_tracts.rds")
obtn_population_by_census_tract <- read_rds("https://github.com/rfortherestofus/obtn/raw/data-2022/inst/obtn_population_by_census_tract.rds")