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
# Sets theme according to color of logo | |
set_color_theme <- function(logo_loc, low_sat = 0.042, high_sat = 0.866, medium_sat = 0.28, | |
low_val = 0.99, high_val = 0.38, medium_val = 0.65) { | |
# Read image/logo as a list | |
img1 <- list(readPNG(file.path(logo_loc))) | |
# Find the average pixel value | |
rgb <- rowMeans(sapply(img1, function(im) apply(im, 3, mean) * 255)) | |
# Convert to HSV - hue, saturation, value | |
img_hsv <- rgb2hsv(rgb[1:3])[,1] | |
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) | |
library(gganimate) | |
library(cowplot) | |
iris_tall <- iris %>% | |
cbind(iris %>% | |
rename_all(function(.) paste0(., "_2")) %>% | |
select(-Species_2)) %>% | |
gather(key = Variable, value = Value, c(1:(ncol(iris) - 1))) %>% | |
gather(key = Variable2, value = Value2, c(2:ncol(iris))) %>% |
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) | |
library(cowplot) | |
library(bartext) # devtools::install_github("Omni-Analytics-Group/bartext") | |
mpg_manu <- mpg %>% | |
distinct(manufacturer, model) %>% | |
mutate_all(tools::toTitleCase) %>% | |
mutate(model = gsub(" 4wd| 2wd| Pickup| Wagon|Toyota ", "", model)) | |
p1 <- ggplot(mpg_manu, aes(x = manufacturer)) + |
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(pdftools) | |
library(tidyverse) | |
parse_tables <- function(url, remove_last = TRUE) { | |
my_data <- pdf_data(url) | |
lapply(my_data, function(my_data2) { | |
header_row <- my_data2 %>% | |
filter(y == min(y)) |
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) | |
polygon_values <- tibble( | |
id = 1:2, | |
value = c(-2, 2) | |
) | |
polygon_positions <- tibble( | |
id = c(1, 1, 1, 2, 2, 2, 2), | |
x = c(1, 2, 3, 5, 6, 7, 6), |
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(magick) | |
library(tidyverse) | |
im <- image_read("line.jpg") | |
im_proc <- im %>% | |
image_channel("saturation") %>% | |
image_threshold("white", "30%") %>% | |
image_negate() |
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) | |
library(fable) | |
fable_series <- AirPassengers %>% | |
as_tsibble() %>% | |
model( | |
ets = ETS(box_cox(value, 0.3)), | |
arima = ARIMA(value), | |
snaive = SNAIVE(value) | |
) %>% |
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) | |
library(clean) | |
unclean_tbl <- tibble( | |
Logical = c("Yes", "No", "Depends", "Unknown"), | |
Factor = c("bachelor's", "Bachelor's Degree", "Master's Degree", "PhD"), | |
Currency = c("$20", "$ 25", "26.02", "$27.0"), | |
Numeric = c("~15", "about 10", "20", "15") | |
) |
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(ggplot2) | |
ggplot(data = diamonds, aes(x = carat, y = price, colour = clarity)) + | |
geom_point() + | |
scale_y_continuous(labels = scales::dollar, | |
breaks = scales::breaks_width(2000)) + | |
scale_x_continuous(breaks = scales::breaks_width(.5)) | |
ggplot(data = diamonds, aes(x = carat, y = price, colour = clarity)) + | |
geom_point() + |
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) | |
library(ggrepel) | |
ln <- read_csv("Investment_Bubble_Cycle_Line.csv") %>% | |
mutate(Y = Y + 50 + 28) | |
cv <- read_csv("Investment_Bubble_Cycle.csv") %>% | |
mutate(Y = Y + 50) | |
mapping = tibble( | |
X = cv$X[c(20, 50, 70, 75, 105, 125, 138, 150, 175, 165, 185, 208, 225, 255, 280)], |
OlderNewer