Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
AlbertRapp / twitter_tracking.R
Last active May 12, 2022 23:49
Get Dataviz from Twitter into your note-taking system using R
### Change these parts here ----------------------------------------------------
# Set to your working directory where there is a template.md file
setwd(here::here())
# Locations
vault_location <- stop('Add Vault Location') # Location of markdown files
attachments_dir <- stop('Add Vault Subdirectory Location') # subdirectory of vault_location for png-files
imap_mail <- stop('Set imap mail client') # mail client
library(tidyverse)
dat <- mpg %>%
mutate(
custom_color = if_else(
year == 2008 & manufacturer == 'audi',
'dodgerblue4',
'grey80'
)
)
@AlbertRapp
AlbertRapp / ggflowchart.qmd
Last active November 4, 2022 03:14
ggplot flowchart
---
output: html_document
editor_options:
chunk_output_type: console
---
This is based on Nicola Rennie's blog post https://nrennie.rbind.io/blog/2022-06-06-creating-flowcharts-with-ggplot2/
The flowchart is taken from https://imgur.com/gallery/79VHL
@AlbertRapp
AlbertRapp / polar_coord_legend.R
Created June 7, 2022 14:54
polar_coord_legend.R
camcorder::gg_record(
dir = 'img',
height = 16,
width = 16,
units = 'cm'
)
library(tidyverse)
library(ggforce)
dat <- tibble(
@AlbertRapp
AlbertRapp / street_map_game_mechanics.qmd
Created June 19, 2022 14:59
Testing out the mechanics for a shiny web app/game with maps and street names
---
output: html_document
editor_options:
chunk_output_type: console
---
## Load Packages
```{r}
setwd(here::here('streep_map_game/'))
@AlbertRapp
AlbertRapp / nycflights_calender.qmd
Created July 9, 2022 11:15
NYC flights calendar plot
library(tidyverse)
color_palette <- thematic::okabe_ito(8)
flights <- nycflights13::flights
counts <- flights %>%
mutate(
date = lubridate::make_date(year = year, month = month, day = day)
) %>%
count(date) %>%
mutate(
@AlbertRapp
AlbertRapp / stacked_bar_plot_alternative.qmd
Last active June 27, 2023 13:01
How to split bars instead of stacking them
---
output: html_document
editor_options:
chunk_output_type: console
---
```{r}
setwd(here::here('stacked_bar_alternative/'))
camcorder::gg_record(
dir = 'img',
@AlbertRapp
AlbertRapp / responsive_tabsets.qmd
Created July 25, 2022 13:17
Responsive tabsets
```{r}
#| message: false
library(tidyverse)
```
::: panel-tabset
## Responsive
@AlbertRapp
AlbertRapp / across_and_tidyselect.R
Created August 27, 2022 08:26
across_and_tidyselect
library(tidyverse)
# GOAL: Center and standardize every numeric column but `year` (by species and island)
palmerpenguins::penguins
# # A tibble: 344 x 8
# species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex year
# <fct> <fct> <dbl> <dbl> <int> <int> <fct> <int>
# 1 Adelie Torgersen 39.1 18.7 181 3750 male 2007
# 2 Adelie Torgersen 39.5 17.4 186 3800 female 2007
@AlbertRapp
AlbertRapp / data_viewer_app.R
Created August 29, 2022 14:29
This is a non-modularized Shiny app to explore different data sets.
setwd(here::here('shiny_modules'))
library(shiny)
library(ggplot2)
ui <- fluidPage(
theme = bslib::bs_theme(
# Colors (background, foreground, primary)
bg = 'white',
fg = '#06436e',
primary = colorspace::lighten('#06436e', 0.3),