Skip to content

Instantly share code, notes, and snippets.

View maxdrohde's full-sized avatar

Maximilian Rohde maxdrohde

View GitHub Profile
library(MASS)
library(plotrix)
library(tidyverse)
library(gganimate)
####################################
## Example 1 (Data by Group with means and estimated means)
####################################
## Number of groups, observations per group
@maxdrohde
maxdrohde / plot.R
Created August 31, 2023 23:40
patchwork + ggtext example
library(ggplot2)
library(patchwork) # For composing plots
# See https://patchwork.data-imaginist.com/
library(ggtext) # For formatting text using markdown syntax
# See https://wilkelab.org/ggtext/
# Make a ggplot histogram from a vector of data
gg_hist <- function(x){
data.frame(x) |>
@maxdrohde
maxdrohde / display.R
Created January 15, 2024 20:57
display.R
# Display data frame as a nicely formatted and interactive GT table
display <- function(df){
df |>
gt::gt() |>
gt::opt_interactive(use_search = TRUE,
use_compact_mode = TRUE,
use_text_wrapping = TRUE) |>
gt::opt_stylize(style = 2) |>
gt::cols_width(everything() ~ px(250))
}
@maxdrohde
maxdrohde / parallel_analysis.R
Created March 13, 2025 00:37
See how parallel computing is working in practice vs optimal speedup
library(furrr)
x <- numeric()
for (i in 1:20) {
future::plan(multisession, workers = i)
result <- system.time({
r <- furrr::future_map(1:100,
~ sum(rnorm(1e7)),
.options = furrr_options(seed=TRUE))
# Load packages
library(tidyverse)
library(gganimate)
library(tidymodels)
set.seed(2021)
# Generate true relationship between x and y as piecewise
piecewise <- function(x) {
case_when(