Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
AlbertRapp / fruit_seasonality_New_Zealand.qmd
Created August 7, 2023 20:58
fruit_seasonality_New_Zealand.qmd
```{r}
library(tidyverse)
# https://www.produce.co.nz/seasonality-chart/
fruits <- tibble::tribble(
~ fruit, ~start, ~ end,
"Blueberry", "October", "April",
@AlbertRapp
AlbertRapp / split_stacked_bar_charts_YT.R
Created May 6, 2023 09:18
split_stacked_bar_charts_YT.qmd
library(tidyverse)
mpg_2008 <- mpg |>
filter(
year == 2008,
!(class %in% c('2seater', 'minivan'))
) |>
mutate(
class = case_when(
class %in% c('compact', 'subcompact') ~ '(Sub-)Compact',
@AlbertRapp
AlbertRapp / maps_instead_of_for_loops.R
Created April 21, 2023 08:52
maps_instead_of_for_loops.R
library(tidyverse)
dat <- gapminder::gapminder
####### For loop approach
slopes <- numeric(5)
names(slopes) <- unique(dat$continent)
for (selected_continent in unique(dat$continent)) {
filtered_data <- dat |>
@AlbertRapp
AlbertRapp / dot-columns-gt.R
Created April 8, 2023 10:59
dot-columns-gt.R
library(tidyverse)
library(gt)
circle <- '<span style="
display: inline-block;
background-color: pink;
width: 1cm;
height: 1cm;
border-radius: 100%;
border: black 1px solid;
@AlbertRapp
AlbertRapp / perfect_bar_chart.qmd
Created April 7, 2023 10:14
Perfect bar charts
```{r}
library(tidyverse)
manufacturers <- mpg |>
mutate(manufacturer = str_to_title(manufacturer))
```
```{r}
@AlbertRapp
AlbertRapp / interactive_gt.R
Created April 2, 2023 15:20
interactive_gt.R
library(gt)
gt::towny |> # new data set in {gt} 0.9.0
dplyr::select(name, land_area_km2) |>
gt() |>
cols_label(name = 'Name', land_area_km2 = 'Area (sq.km)') |>
opt_interactive(
use_search = TRUE, use_filters = TRUE,
use_compact_mode = TRUE, page_size_default = 5
) |>
tab_options(table.width = '500px', container.width = '500px')
@AlbertRapp
AlbertRapp / 01_gt_gtExtras_incorporated.R
Created April 2, 2023 15:18
01_gt_gtExtras_incorporated.R
library(gt)
library(tidyverse)
tribble(
~flag, ~country, ~population,
'DE', 'Germany', 84270625,
'US', 'United States', 333287557,
'IE', 'Italy', 58853482,
'GY', 'Guyana', 795408,
'NO', 'Norway', 5488984,
'GH', 'Ghana', 32103042
@AlbertRapp
AlbertRapp / shiny-styling-thread.qmd
Created March 27, 2023 09:12
shiny-styling-thread.qmd
## No styling app
```{r}
setwd(here::here())
library(shiny)
library(tidyverse)
penguins <- palmerpenguins::penguins |> filter(!is.na(sex))
# Define UI
@AlbertRapp
AlbertRapp / shiny_modules_60_seconds.R
Created March 21, 2023 15:18
shiny_modules_60_seconds.R
setwd(here::here('02_shiny_modules'))
library(shiny)
library(ggplot2)
ui <- fluidPage(
theme = bslib::bs_theme(bootswatch = 'flatly'),
tabsetPanel(
tabPanel("Penguins", {
sidebarLayout(
@AlbertRapp
AlbertRapp / icon_dice.qmd
Created March 14, 2023 20:43
icon_dice.qmd
```{r}
library(tidyverse)
library(showtext)
library(ggtext)
font_add('fa-solid', '00_fonts/Font Awesome 6 Free-Solid-900.otf')
showtext_auto()
showtext_opts(dpi = 300)