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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` 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': | |
#> |
- Eurostat, World Bank and others: https://ikashnitsky.github.io/2017/data-acquisition-two/
- Star Wars data: in dplyr, http://dplyr.tidyverse.org/reference/starwars.html
- Baby names data: babynames package, https://cran.r-project.org/web/packages/babynames/index.html
- Movies data: https://cran.r-project.org/web/packages/ggplot2movies/index.html ggplot2movies package
- Game of Thrones screen time: https://github.com/Preetish/GoT_screen_time
- Open Bike Data: https://github.com/ropensci/bikedata
- Tons of data through 538: https://cran.r-project.org/web/packages/fivethirtyeight/vignettes/fivethirtyeight.html
- Public health data England: fingertipsR, https://cran.r-project.org/web/packages/fingertipsR/
- Financial data via Quandl: https://www.quandl.com/tools/r
- Cyclones: https://github.com/ropensci/rrricanesdat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(V8) | |
library(xml2) | |
library(httr) | |
library(rvest) | |
library(stringi) | |
library(tidyverse) | |
get_page <- function(num=1, seed=Sys.Date()) { | |
GET( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
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:
NewerOlder