Skip to content

Instantly share code, notes, and snippets.

View timcdlucas's full-sized avatar

Tim Lucas timcdlucas

View GitHub Profile
#'---
#'output:
#' pdf_document:
#' number_sections: true
#' toc: true
#' toc_depth: 2
#' keep_tex: true
#'title: "test"
#'author: Tim Lucas
@timcdlucas
timcdlucas / alpha_ribbon.R
Created January 7, 2020 14:11
alpa ribbons
head(mtcars)
a <- 0.1
ggplot(mtcars, aes(mpg, disp)) +
geom_smooth(method = 'lm', level = 0.99, alpha = a) +
geom_smooth(method = 'lm', level = 0.97, alpha = a) +
geom_smooth(method = 'lm', level = 0.94, alpha = a) +
geom_smooth(method = 'lm', level = 0.92, alpha = a) +
@timcdlucas
timcdlucas / fct_reorder.R
Created November 26, 2019 11:00
Use fct_reorder in facet_wrap
library(forcats)
library(ggplot2)
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
facet_wrap(~ factor(gear))
ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point() +
@timcdlucas
timcdlucas / pals.R
Created November 25, 2019 14:16
palettes and patchwork
# devtools::install_github("thomasp85/patchwork")
library(patchwork)
library(paletteer)
library(ggplot2)
ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
geom_point() +
scale_colour_paletteer_d('palettetown', 'spearow') +
ggtitle('Spearow loves mtcars') +
@timcdlucas
timcdlucas / pca_log.R
Created October 4, 2019 18:47
pca with log + eps
# pca
d <- data.frame(x = runif(100))
d$y <- d$x + runif(100, -0.01, 0.01)
plot(y ~ x, data = d)
@timcdlucas
timcdlucas / dist_to_point.R
Created October 4, 2019 09:28
A markdown script for looking at geographic random forests.
#'---
#'output:
#' pdf_document:
#' number_sections: true
#' toc: true
#' toc_depth: 2
#'title: "RandomForest with distance to points"
#'author: Tim Lucas
#'fontsize: 8pt
library(dplyr)
# If we don't have 'TOYOTA PRADO' in the set?
test <- c('ROVER', 'CRUISER', 'TOYOTA', 'TOYOTA PRADO', 'NISSAN')
old <- c('ROVER', 'CRUISER', 'TOYOTA')
new <- c('LandRover', 'LandRover', 'Toyota')
@timcdlucas
timcdlucas / orth.R
Created July 9, 2019 08:33
Orthogonal polygnomials
library(ggplot2)
set.seed(1001)
start <- 2
end <- 20
N <- 100
x <- runif(N, start, end)
library(caret)
library(dplyr)
data(diamonds)
train_i <- sample(c(FALSE, TRUE), nrow(diamonds), replace = TRUE, prob = c(0.2, 0.8))
# Make data with biased train2 set
d <- data.frame(x = runif(300, 0, 5))
d$y <- d$x + rnorm(300)
d$g <- c('train1', 'train2', 'test')
d$y[d$g == 'train2'] <- d$y[d$g == 'train2'] + 5
plot(d$x, d$y, col = factor(d$g))