Skip to content

Instantly share code, notes, and snippets.

View jkaupp's full-sized avatar

Jake Kaupp jkaupp

View GitHub Profile
gen_plot <- function(xvals = c(1,12), yvals = c(1,10), n = 10,
distance = seq(-3,3,length.out =n),
seed = NULL, palette = c("red", "blue")){
# adapted from: https://stackoverflow.com/questions/50275195/
segment.shift <- function(x1,x2,y1,y2, d){
# calculate vector
v <- c(x2 - x1,y2 - y1)
# Inspired by Nadieh Bremer's lasso annotations here: https://twitter.com/NadiehBremer/status/1277622602735865856
# h/t Cedric Scherer: https://twitter.com/CedScherer/status/1278351840074240001
library(ggplot2); library(ggforce)
add_lasso_layer <- function(x1, x2, y) {
width = x2 - x1
space = width * 0.05
lasso_points = data.frame(
@gkaramanis
gkaramanis / leaf.R
Last active August 14, 2019 13:00
Draw a leaf with closed b-spline shape in ggforce
library(ggforce)
library(ggplot2)
leaf <- data.frame(
x = c(1.6, 1.5, 1.8, 1.5, 1.6, 1.3),
y = c(2, 2, 1.5, 1, 1, 1.5)
)
ggplot(leaf, aes(x, y)) +
geom_polygon(fill = NA, colour = 'grey') +
library(tidyverse)

# See https://stackoverflow.com/a/17313561/120898
pts <- function(x) {
  as.numeric(grid::convertUnit(grid::unit(x, "pt"), "mm"))
}

df <- tibble(x = 1:10, y = 1:10)
@Torvaney
Torvaney / calendar.R
Last active March 28, 2021 00:03
Make a circular calendar in ggplot2
library(tidyverse)
year <- 2019
start_date <- lubridate::date(str_glue("{year}-01-01")) # there must be a better way??
month_colours <- c(
"January" = "#a5cdff",
"February" = "#c9e1ff",
"March" = "#b2edb6",
``` r
library(purrr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
library(V8)
library(xml2)
library(httr)
library(rvest)
library(stringi)
library(tidyverse)
get_page <- function(num=1, seed=Sys.Date()) {
GET(
@hrbrmstr
hrbrmstr / gg_tweet.R
Last active October 16, 2020 04:49
use the magick device to make ggplots conform to twitter card or in-stream image optimal sizes, with or without "retina" resolution
library(httr)
library(magick)
library(hrbrthemes)
library(ggplot2)
theme_tweet_rc <- function(grid = "XY", style = c("stream", "card"), retina=TRUE) {
style <- match.arg(tolower(style), c("stream", "card"))
switch(
@davidofwatkins
davidofwatkins / google-fonts-sync-git.md
Last active June 26, 2024 13:53
Keep MacOS Fonts Updated with Google Fonts

Google Fonts suggests syncing fonts to your computer with a tool called SkyFonts. However, if you're running MacOS and want to keep your machine updated with all Google Fonts without any extra software, you can do this with Git, thanks to the Google Fonts Repo.

To do this, run the following in your terminal:

cd ~/Library/Fonts/
git clone --depth 1 https://github.com/google/fonts.git google-fonts

Done! In the future, you can download new fonts by running: