Skip to content

Instantly share code, notes, and snippets.

View eleakin's full-sized avatar

Eric L. Eakin eleakin

View GitHub Profile
@eleakin
eleakin / tx_la_weather_alerts.R
Created August 26, 2020 15:56 — forked from ianmcook/tx_la_weather_alerts.R
Map of active weather alerts for Texas and Louisiana
remotes::install_github("ianmcook/weatherAlerts")
remotes::install_github("ianmcook/weatherAlertAreas")
library(weatherAlerts)
library(leaflet)
alerts <- getAlerts(c("TX", "LA")) # takes about 45 seconds
severity <- alerts@data$severity
colorMap <- c(Minor = "green",
/* rs-theme-name: Idle Eyes */
/* rs-theme-is-dark: TRUE */
.ace_gutter {
background: #3b3b3b;
color: rgb(153,153,153)
}
.ace_print-margin {
width: 1px;
background: #555;
}
@eleakin
eleakin / US Zip Codes from 2013 Government Data
Created April 17, 2019 21:40 — forked from erichurst/US Zip Codes from 2013 Government Data
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
# Takes an ordered vector of numeric values and returns a small bar chart made
# out of Unicode block elements. Works well inside dplyr mutate() or summarise()
# calls on grouped data frames.
sparkbar <- function(values) {
span <- max(values) - min(values)
if(span > 0 & !is.na(span)) {
steps <- round(values / (span / 7))
blocks <- c('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '')

This hit #rstats today:

Has anyone made a dumbbell dot plot in #rstats, or better yet exported to @plotlygraphs using the API? https://t.co/rWUSpH1rRl

— Ken Davis (@ken_mke) October 23, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

So, I figured it was worth a cpl mins to reproduce.

While the US gov did give the data behind the chart it was all the data and a pain to work with so I used WebPlotDigitizer to transcribe the points and then some data wrangling in R to clean it up and make it work well with ggplot2.

It is possible to make the top "dumbbell" legend in ggplot2 (but not by using a guide) and color the "All Metro A

@eleakin
eleakin / spreadsheet.py
Created December 28, 2017 20:25 — forked from alchemyst/spreadsheet.py
Spreadsheet in 100 lines of Python
#!/usr/bin/env python
import tkinter as tk
import math
import re
from collections import ChainMap
Nrows = 5
Ncols = 5
@eleakin
eleakin / csv2txts.R
Created November 27, 2017 16:42 — forked from benmarwick/csv2txts.R
Convert a single CSV file (one text per row) into separate text files. A function in R.
#' Making several text files from a single CSV file
#'
#' Convert a single CSV file (one text per row) into
#' separate text files. A function in R.
#'
#' To use this function for the first time run:
#' install.packages("devtools")
#' then thereafter you just need to load the function
#' fom github like so:
#' library(devtools) # windows users need Rtools installed, mac users need XCode installed
@eleakin
eleakin / text2csv.R
Created November 23, 2017 17:27 — forked from benmarwick/test.R
Convert a folder of text files into a single CSV file with one column for the file names and one column of the text of the file. A function in R.
#' Compiling several text files into a single CSV file
#'
#' Convert a folder of text files into a single CSV file
#' with one column for the file names and one column of the
#' text of the file. A function in R.
#'
#' To use this function for the first time run this next line:
#' install.packages("devtools")
#' then thereafter you just need to load the function
#' fom github like so, with these two lines:
@eleakin
eleakin / README.md
Created September 22, 2017 15:06 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@eleakin
eleakin / gauge-post.R
Created June 13, 2017 21:52 — forked from pravj/gauge-post.R
Source code for the post "Gauge charts in R and Python" [R version]
library(plotly)
base_plot <- plot_ly(
type = "pie",
values = c(40, 10, 10, 10, 10, 10, 10),
labels = c("-", "0", "20", "40", "60", "80", "100"),
rotation = 108,
direction = "clockwise",
hole = 0.4,
textinfo = "label",