Skip to content

Instantly share code, notes, and snippets.

View trinker's full-sized avatar

Tyler Rinker trinker

  • Kangarootime
  • Buffalo, NY
View GitHub Profile
@trinker
trinker / images_as_xaxis_labels_updated.R
Created March 4, 2017 17:32 — forked from jonocarroll/images_as_xaxis_labels_updated.R
Implements @baptiste's much better method for making this work
library(ggplot2) ## devtools::install_github("hadley/ggplot2)
library(grid) ## rasterGrob
library(EBImage) ## readImage
library(ggthemes) ## theme_minimal
## ##########
## INDEPENDENT CODE TO BE SOURCED:
## ##########
# user-level interface to the element grob
@trinker
trinker / images_as_xaxis_labels_updated.R
Created March 4, 2017 17:32 — forked from jonocarroll/images_as_xaxis_labels_updated.R
Implements @baptiste's much better method for making this work
library(ggplot2) ## devtools::install_github("hadley/ggplot2)
library(grid) ## rasterGrob
library(EBImage) ## readImage
library(ggthemes) ## theme_minimal
## ##########
## INDEPENDENT CODE TO BE SOURCED:
## ##########
# user-level interface to the element grob
@trinker
trinker / Norah's Graphs
Last active January 27, 2019 00:26
Norah's Graphs
pacman::p_load(tidyverse, ggrepel)
set.seed(10)
norah <- data_frame(
right = c(4, 7, 2, 9, 6, 3, 8, 10),
up = c(10, 8, 3, 6, 9, 2, 7, 4),
size = c(1, 1, 2, 3, 4, 9, 8, 7),
high = sample(size),
friends = c('Makayla', 'Ethan', 'Jolene', "Maddy", "Isla", "Daddy", "Norah", "Lila"),
@trinker
trinker / sales funnel
Created February 14, 2017 17:51
sales funnel
library(tidyverse)
set.seed(11)
dat <- data_frame(
stage = LETTERS[1:7],
n = sample(20:100, length(stage))
)
dat %>%
mutate(
@trinker
trinker / headless browser
Created February 14, 2017 16:02
headless browser
if (!require("pacman")) install.packages("pacman")
pacman::p_load_gh("ropensci/RSelenium")
pacman::p_load(httr, jsonlite, XML, RSelenium, curl, semver, rappdirs, subprocess, rvest, xml, geosphere, tidyverse)
## Constants
hillsgrove <- data.frame(long = -76.710563, lat = 41.443678)
earth_radius_miles <- 3959 #in miles
## Cities to lookup
@trinker
trinker / sentiment blog
Created February 12, 2017 03:01
sentiment blog
pacman::p_load(tidyverse, textclean, textshape, textreadr, sentimentr, rvest, xml2, yaml)
posts <- file.path('https://github.com/iacobus42/blog/tree/master/_posts') %>%
read_html() %>%
html_nodes(xpath = '//*[@id="js-repo-pjax-container"]/div[2]/div[1]/div[3]/table') %>%
html_table() %>%
`[[`(1) %>%
select(X2) %>%
slice(-c(1:2)) %>%
unlist(use.names = FALSE)
pacman::p_load(termco, textshape, textclean, termco, xtable)
pacman::p_load_current_gh('trinker/hilight')
presidential_debates_2012 <- termco::presidential_debates_2012
#' See Terms in Context
#'
#' Examine regex term selections in the context of n rows before and after.
#'
#' @param x A data.frame with a text column.
#' @param regex A regular expression that will be highlighted.
#' Add a Column as Rownames
#'
#' Takes an existing column and uses it as rownames instead. This is useful
#' when turning a \code{\link[base]{data.frame}} into a \code{\link[base]{matrix}}.
#' Inspired by the \pkg{tibble} package's \code{column_to_row} which is now
#' deprecated.
#'
#' @param x An object that can be coerced to a \code{\link[base]{data.frame}}.
#' @param loc The column location as either an integer or string index location.
#' Must be unique row names.
@trinker
trinker / ggplot2_labels_on_top.txt
Created January 13, 2017 14:55
ggplot2 labels on top
library(reshape2)
library(ggplot2)
data(mtcars)
dat <- with(mtcars, data.frame(mpg, cyl, disp, hp, wt, gear))
cor.matrix <- round(cor(dat, use = "pairwise.complete.obs", method = "spearman"), digits = 2)
diag(cor.matrix)<-NA
cor.dat <- melt(cor.matrix)
cor.dat <- data.frame(cor.dat)
@trinker
trinker / check_install
Created January 3, 2017 02:06
check_install
check_install <- function(x, fun = 'function'){
found <- TRUE
path <- try(find.package(x), silent = TRUE)
if (inherits(path, "try-error")) found <- FALSE
if (!found) {
if (interactive()){
message(paste(x, "package not found. Do you want to install?\n"))
ans <- utils::menu(c("Yes", "No"))