Skip to content

Instantly share code, notes, and snippets.

View swo's full-sized avatar

Scott Olesen swo

View GitHub Profile
@swo
swo / polars_cheat_sheet.py
Last active December 6, 2023 03:24
Polars cheat sheet
import polars as pl
# Making data frames ------------------------------------------
# with dictionary
df = pl.DataFrame({
'name': ['foo', 'bar', 'baz'],
'bar': [0, 1, 2],
'qux': [0.0, 1.0, 2.0]
})
@swo
swo / two-axis-example.R
Last active March 18, 2022 15:54
Making a second axis on ggplot
library(tidyverse)
# "faithful" is a dataset about a geyser, showing size of eruption vs. waiting
# time before the eruption
data <- as_tibble(datasets::faithful) %>%
mutate(index = 1:n()) %>%
head(10)
data
@swo
swo / sigfig.R
Created December 2, 2019 19:34
significant figures
sigfig <- function(x, n = 2) {
formatC(signif(x, digits = n), digits = n, format = "fg", flag = "#")
}
@swo
swo / italic_facets.R
Last active August 30, 2024 02:37
Italics in ggplot facet labels
# Say I have some short-hand labels like "Ec/q",
# which actually stand for "E. coli & quinolones",
# but I want "E. coli" to be in italics
library(tidyverse)
n <- 100
tibble(
x = rnorm(n),