Skip to content

Instantly share code, notes, and snippets.

Avatar

James Curley jalapic

View GitHub Profile
@abresler
abresler / get_nba_days_scores.r
Last active Dec 18, 2015
Gets game scores and more for any valid NBA date
View get_nba_days_scores.r
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 Oct 2, 2015
Fixed nodes (with specified positions) in DiagrammeR
View diagrammer-fixed-nodes-visnetwork.R
# 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")
View geom_flat_violin.R
# 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
Repel text labels away from each other in a ggplot2 figure.
View plot_repel.R
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 Aug 29, 2015 — forked from jalapic/gana.csv
Heatmap of touches (in rbokeh)
View Readme.md

@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 Apr 24, 2018
R function to auto generate heat map shot charts, need help completing court drawing then to complete
View plot_player_shot_chart.r
#' 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 Jul 19, 2015
viridis color/fill scales for ggplot2
View viridis_scales.R
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 Oct 31, 2016
Stacked Bump Chart
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body{
margin: 0px;
font: 10px sans-serif;
}
path.player{
@abresler
abresler / gist:6911f5eb5d3834fc6d55
Last active Aug 29, 2015
gotham_cookies_graphviz
View gist:6911f5eb5d3834fc6d55
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 Jul 19, 2020
Recreating Edward Tufte's New York City Weather Visualization
View tufte
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) %>%