Skip to content

Instantly share code, notes, and snippets.

View jalapic's full-sized avatar

James Curley jalapic

View GitHub Profile
@abresler
abresler / get_nba_days_scores.r
Last active December 18, 2015 15:11
Gets game scores and more for any valid NBA date
packages <- #need all of these installed including some from github
c('dplyr',
'magrittr',
'jsonlite',
'tidyr',
'stringr',
'lubridate')
options(warn = -1)
lapply(packages, library, character.only = T)
@rich-iannone
rich-iannone / diagrammer-fixed-nodes-visnetwork.R
Last active October 2, 2015 03:34
Fixed nodes (with specified positions) in DiagrammeR
# Installation
#install.packages("devtools")
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
# Create and render an empty graph
empty_graph <- create_graph()
render_graph(empty_graph, output = "visNetwork")
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@slowkow
slowkow / plot_repel.R
Last active May 2, 2018 21:07
Repel text labels away from each other in a ggplot2 figure.
library(ggplot2)
library(FField)
# You'll have to play with repulsion, cex.x, and cex.y to get satisfactory results.
plot_text <- function(x, y, label, repulsion = 1, cex.x = 110, cex.y = 40) {
dat <- data.frame(xpos = x, ypos = y, label = label)
dat$label <- as.character(dat$label)
# Use the FField package to repel the text labels away from each other.
dat <- cbind(
@timelyportfolio
timelyportfolio / Readme.md
Last active August 29, 2015 14:28 — forked from jalapic/gana.csv
Heatmap of touches (in rbokeh)

@jalapic did these really nice set of touch heatmap charts. On Twitter, there was a discussion how to do this interactively with d3.js or some other JavaScript. I definitely have some ideas how to accomplish this, but for now let's see how we can kind of do it in rbokeh. There is just a small issue with palette selection in Bokeh that does not let us allow a no color that prevents us from getting really close.

## https://gist.github.com/jalapic/3616c0197ece24060e99
library(rbokeh)
library(dplyr)

gana <- read.csv("https://gist.githubusercontent.com/jalapic/3616c0197ece24060e99/raw/2bc2361c5fceb9be80dece9b7ffa14d129a3edfb/gana.csv")

figure() %>%
@abresler
abresler / plot_player_shot_chart.r
Last active April 24, 2018 18:52
R function to auto generate heat map shot charts, need help completing court drawing then to complete
#' NBA Player Shot Chart
#'
#' @param player name the player, must be exact
#' @param author, year_end_season: numeric end of season
#'
#' @return
#' @export
#'
#' @examples boggie_bog <- plot_player_shot_chart(player = "Bojan Bogdanovic",
#year_season_end = 2015, exclude_backcourt = T
@hrbrmstr
hrbrmstr / viridis_scales.R
Created July 19, 2015 18:45
viridis color/fill scales for ggplot2
viridis_pal <- function(alpha=1) {
function(n) {
viridis(n, alpha)
}
}
scale_color_viridis <- function(..., alpha=1, discrete=TRUE) {
if (discrete) {
discrete_scale("colour", "viridis", viridis_pal(alpha), ...)
@1wheel
1wheel / index.html
Last active October 31, 2016 17:58
Stacked Bump Chart
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body{
margin: 0px;
font: 10px sans-serif;
}
path.player{
@abresler
abresler / gist:6911f5eb5d3834fc6d55
Last active August 29, 2015 14:15
gotham_cookies_graphviz
library(rvest)
library(htmltools)
library(pipeR)
library("DiagrammeR")
html('
<ul class="ze_imagelist" style="width:925px;height:400px;" id="slideshowpj_widget_54da647bbdf7e"><li class="ze_thumb ze_type_image ze_item_number_1"><a class="ze_box" rel="prettyPhoto[pj_widget_54da647bbdf7e]" href="http://ec12.cdn.cincopa.com/SaltedCaramel2.jpg?o=1&amp;res=76&amp;cdn=ec&amp;p=y&amp;pid=231720&amp;ph3=b2d1timslim1sat2p2lxtiganpc1chim&amp;d=AMWAjFwULOAANQJsAMnyJRB&amp;as=mp3" title="Salted Caramel - Our Signature Cookie<br />Our Signature Cookie! Caramel-infused dough loaded with Chocolate Chips and drizzled with Salted Caramel Sauce" style="width:190px;height:190px;"> <div class="ze_overlay"></div> <div id="pj_widget_54da647bbdf7e_0_thumbsplash" class="ze_item" style="width:190px;height:190px;"> <img class="ze_postar" style="height:190px;" src="http://ec12.cdn.cincopa.com/SaltedCaramel2.jpg?o=1&amp;res=76&amp;cdn=ec&amp;p=y&amp;pid=231720&amp;ph3=b2d1timslim1sat2p2lxtiganpc1chim&amp;d=AMWAjFwULOAANQJsAMnyJRB" t
@abresler
abresler / tufte
Last active July 4, 2023 18:56
Recreating Edward Tufte's New York City Weather Visualization
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2)
"http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYNEWYOR.txt" %>%
read.table() %>% data.frame %>% tbl_df -> data
names(data) <- c("month", "day", "year", "temp")
data %>%
group_by(year, month) %>%