Skip to content

Instantly share code, notes, and snippets.

View z3tt's full-sized avatar
👨‍💻
Coding at home

Cédric Scherer z3tt

👨‍💻
Coding at home
View GitHub Profile
@z3tt
z3tt / github.R
Last active April 4, 2024 18:24
Configure GitHub for Rstudio
#### 1. Sign up at GitHub.com ################################################
## If you do not have a GitHub account, sign up here:
## https://github.com/join
# ----------------------------------------------------------------------------
#### 2. Install git ##########################################################
## If you do not have git installed, please do so:
@z3tt
z3tt / penguins_rainclouds.R
Created July 3, 2022 18:30
Polished raincloud plot using the Palmer penguins data
library(palmerpenguins)
library(ggtext)
library(colorspace)
library(ragg)
url <- "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/master/man/figures/lter_penguins.png"
img <- magick::image_read((url))
pic <- grid::rasterGrob(img, interpolate = TRUE)
pal <- c("#FF8C00", "#A034F0", "#159090")
@z3tt
z3tt / data-ggplot-evolution-vol1.r
Last active December 9, 2023 05:16
Data for the blog post "The Evolution of a ggplot (Vol. 1)"
library(tidyverse)
df_students <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-07/student_teacher_ratio.csv")
df_world_tile <- readr::read_csv("https://gist.githubusercontent.com/maartenzam/787498bbc07ae06b637447dbd430ea0a/raw/9a9dafafb44d8990f85243a9c7ca349acd3a0d07/worldtilegrid.csv") %>%
mutate(
## Namibias two-digit country code is handled as `NA` - let us fix that
alpha.2 = if_else(name == "Namibia", "NA", alpha.2),
## We are going to split "Americas" into "North America" and "Sout America"
region = if_else(region == "Americas", sub.region, region),
@z3tt
z3tt / bars_inside_labels.R
Last active October 29, 2023 04:17
Create colorful bar charts with percentage labels inside each bar
library(tidyverse)
library(systemfonts)
mpg_sum <- mpg %>%
## just use 2008 data
dplyr::filter(year == 2008) %>%
## turn into lumped factors with capitalized names
dplyr::mutate(
manufacturer = stringr::str_to_title(manufacturer),
manufacturer = forcats::fct_lump(manufacturer, n = 10)
@z3tt
z3tt / human-rights-protection-scores.R
Created December 29, 2022 18:51
Human Rights Protection Scores of USA and Germany
## packages
library(ggplot2)
library(dplyr)
library(tidyr)
library(ggbraid)
library(colorspace)
library(owidR)
# plus ggtext via namespace
@z3tt
z3tt / imp_berlin.R
Last active November 22, 2022 03:53
Imperviousness levels in and around Berlin, Germany
library(tidyverse)
library(sf)
library(terra)
library(stars)
library(ggspatial)
library(systemfonts)
library(patchwork)
register_variant(
name = "Input Mono Light",
@z3tt
z3tt / 11_circular.R
Last active April 14, 2022 04:49
Create circular scatter plots of daily temperatures for selected cities
library(tidyverse)
## data:
## https://www.kaggle.com/datasets/sudalairajkumar/daily-temperature-of-major-cities?resource=download
temp <- read_csv(here::here("city_temperature.csv"))
## select a few interesting city around the world
temp_selected <-
temp %>%
#filter(str_detect(City, "New York|London|Helsinki|Shanghai|Rio|Jakarta|Cairo|Canberra|Delhi|Capetown|Hong Kong|Reykjavik")) %>%
@z3tt
z3tt / paygap_eustat_eu_dumbbell.Rmd
Last active March 24, 2022 21:15
Dumbbell Chart of Pay Gaps in Europe
---
title: "Gender Pay Gap: Dumbbell Plot (EU only)"
author:
- name: "Cédric Scherer"
url: www.cedricscherer.com
output:
distill::distill_article:
highlight: kate
code_folding: false
toc: true
@z3tt
z3tt / colors.R
Created November 5, 2021 15:22
Create custom ggplot scales
#' Function to extract Jupiter colors as hex codes
#'
#' @param ... Character names of colors
#'
#' @examples
#' jupiter_colors()
#' jupiter_colors("petrol")
#'
#' @export
jupiter_colors <- function(...) {
@z3tt
z3tt / portland_heat.R
Created June 30, 2021 10:05
Visualizing the Heatwave in Portland in 2021
library(tidyverse)
library(systemfonts)
## data
## via https://projects.oregonlive.com/weather/temps/
df <-
readr::read_csv("https://projects.oregonlive.com/weather/pdx_temps.csv") %>%
mutate(yday = lubridate::yday(date),
year = lubridate::year(date),
decade = year %/% 10 * 10,