Skip to content

Instantly share code, notes, and snippets.

@sharlagelfand
sharlagelfand / labeller
Created Mar 26, 2021
Demonstrating the usage of the argument `labeller = label_wrap_gen()` in the ggplot2 function facet_wrap()
View labeller
library(ggplot2)
library(tibble)
df <- tribble(
~x, ~y, ~label,
1, 2, "A super long label oh god how am I going to deal with this",
2, 1, "A shorter one"
)
# Default - text is cut off
View gist:7245d2293b45399dec9a7f94dc1799ce
library(dplyr)
library(tidyr)
initial <- tibble(
name = c("name_1", "name_2"),
value = list(
tibble(name = c("subname_1", "subname_2"), value = c(1, 2)),
tibble(name = c("subname_3", "subname_4"), value = c(3, 4))
)
)
View rilo kiley albums as ggkeyboard
library(ggkeyboard)
library(ggplot2)
extrafont::loadfonts()
# More adventurous
ggkeyboard(tkl,
palette = c(
background = "#FFFFFF",
keyboard = "#272530",
View datacamp sucks
library(rtweet)
library(dplyr)
library(tidytext)
library(stringr)
library(ggplot2)
library(ggwordcloud)
dc <- search_tweets(
"datacamp",
n = 1000, include_rts = FALSE
View gist:165825299f9a28c768c4cc4b55471919
library(gt)
library(tibble)
acnh_bugs_n <- tribble(
~name, ~price, ~location, ~time, ~months, ~image,
"Yellow butterfly", 160, "Flying", "4 AM - 7 PM", "Mar - Jun, Sep - Oct", "https://vignette.wikia.nocookie.net/animalcrossing/images/f/fa/NH-Icon-yellowbutterfly.png",
"Peacock butterfly", 2500, "Flying by Hybrid Flowers", "4 AM - 7 PM", "Mar - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/8/8f/NH-Icon-peacockbutterfly.png",
"Atlas moth", 3000, "On Trees", "7 PM - 4 AM", "Apr - Sep", "https://vignette.wikia.nocookie.net/animalcrossing/images/6/6a/NH-Icon-atlasmoth.png",
"Centipede", 300, "Hitting Rocks", "4 PM - 11 PM", "Sep - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/3/30/NH-Icon-centipede.png",
"Snail", 250, "On Rocks and Bushes (Rain) ", "All Day", "Jan - Dec", "https://vignette.wikia.nocookie.net/animalcrossing/images/b/b1/NH-Icon-snail.png",
View ACNH flower garden in rstats
library(tidyr)
library(dplyr)
library(forcats)
library(purrr)
library(magick)
items <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/items.csv")
flowers <- items %>%
filter(category == "Flowers") %>%
View theme_fairyfloss
library(ggplot2)
library(dplyr)
library(tidytext)
nintendo <- tribble(
~console, ~sales_type, ~sales_million,
"Nintendo Switch", "Hardware", 52.48,
"Nintendo Switch", "Software", 310.65,
"Nintendo 3DS", "Hardware", 75.71,
"Nintendo 3DS", "Software", 382.22,
View complete() without fill
library(tidyr)
df <- tribble(
~Date, ~Fruit, ~Sold,
"2020-02-01", "Apple", 5,
"2020-02-01", "Banana", 1,
"2020-02-02", "Apple", 2
)
df_complete <- df %>%
View dplyr::all_equal() vs testthat::expect_equal() in testing
library(testthat)
library(dplyr, warn.conflicts = FALSE)
# expect_equal() returns silently if they're the same
expect_equal(iris, iris)
# but with an error if they're not
expect_equal(iris, mtcars)
#> Error: `iris` not equal to `mtcars`.
#> Names: 5 string mismatches
View call. in stop()
divide_by_two <- function(x, call. = FALSE) {
if(!is.numeric(x)) {
stop("IT'S NOT NUMERIC", call. = call.)
} else {
x/2
}
}
divide_by_two(2)
#> [1] 1