Skip to content

Instantly share code, notes, and snippets.

View JoFrhwld's full-sized avatar

Josef Fruehwald JoFrhwld

View GitHub Profile
@JoFrhwld
JoFrhwld / ggplot-color-options.R
Created October 1, 2024 17:10
Setting default colors
options(
ggplot2.discrete.colour = lapply(1:12, ggthemes::ptol_pal()),
ggplot2.discrete.fill = lapply(1:12, ggthemes::ptol_pal()),
ggplot2.ordinal.colour = \(x, ...) scale_color_viridis_d(option = "G", direction = -1, ...),
ggplot2.ordinal.fill = \(x, ...) scale_fill_viridis_d(option = "G", direction = -1, ...),
ggplot2.continuous.colour = \(x,...) scico::scale_color_scico(palette = "batlow", ...),
ggplot2.continuous.fill = \(x,...) scico::scale_fill_scico(palette = "batlow", ...)
)
library(tidyverse)
library(gt)
tibble(
value = 1:6,
name = c(
"one", "two", "three",
"four", "five", "six"
),
die = str_glue(
@JoFrhwld
JoFrhwld / install_brms.R
Created June 16, 2023 15:33
My brms install as of 2023-06-16
# I don't understand why or how this
# plus what's in Makevars works, but it's
# the only way I can get rstan & brms installed\
# see also: https://github.com/stan-dev/rstan/issues/1070#issuecomment-1570565599
# renv::init(bare = TRUE)
Sys.setenv(MAKEFLAGS = "-j4") # four cores used
install.packages(c("Rcpp", "RcppEigen", "RcppParallel", "StanHeaders"), type = "source")
install.packages("rstan", type = "source")
#!/bin/sh
x="Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
@JoFrhwld
JoFrhwld / align_chunks.py
Last active July 1, 2022 21:41
Given two pandas data frames of time stamped transcription chunks of the same audio, return the smallest possible span of aligned chunks between the two.
import pandas as pd
def align_chunks(X_df, Y_df, A_idx_list, B_idx_list, state, **kwargs):
"""
Given X_df and Y_df, return the dataframes (A_df and B_df) with the
smallest possible span of overlapping transcription chunks.
Function operates recursively.
"""
---
title: "R Notebook"
output: html_notebook
---
Source:
https://edition.cnn.com/election/2016/results/exit-polls
```{r}
---
title: "Building up and evaluating models"
output:
html_notebook:
code_folding: none
css: ../custom.css
theme: flatly
toc: yes
toc_depth: 3
toc_float: yes
---
title: "Building up and evaluating models"
output:
html_notebook:
code_folding: none
css: ../custom.css
theme: flatly
toc: yes
toc_depth: 3
toc_float: yes
library(tweenr)
library(gganimate)
library(ggplot2)
library(tidyverse)
#' define the 4 states
state1 <- data_frame(mean = 0,
sd = 1)
state2 <- data_frame(mean = 0,
sd = 3)
@JoFrhwld
JoFrhwld / purrr_bootstrap.R
Created July 29, 2017 20:06
Using purrr to do bootstrap estimation of the mean
library(tidyverse)
replicates <- (1:100000)%>%
map(~sample(faithful$waiting, replace = T))%>%
map(mean)%>%
simplify()
data_frame(replicates = replicates)%>%
ggplot(aes(replicates))+
stat_density()