Skip to content

Instantly share code, notes, and snippets.

@chichacha
chichacha / Zip Codes to DMAs
Created February 28, 2024 19:45 — forked from clarkenheim/Zip Codes to DMAs
TSV file containing zip codes and the DMA they fall in to. Method: calculate the centre point of every zip code geo boundary, plot those points on a DMA boundary map, find the containing DMA of each zip centroid
This file has been truncated, but you can view the full file.
zip_code dma_code dma_description
01001 543 SPRINGFIELD - HOLYOKE
01002 543 SPRINGFIELD - HOLYOKE
01003 543 SPRINGFIELD - HOLYOKE
01004 543 SPRINGFIELD - HOLYOKE
01005 506 BOSTON (MANCHESTER)
01007 543 SPRINGFIELD - HOLYOKE
01008 543 SPRINGFIELD - HOLYOKE
01009 543 SPRINGFIELD - HOLYOKE
01010 543 SPRINGFIELD - HOLYOKE
@chichacha
chichacha / Ascii Art
Created February 7, 2021 05:00
ASCII Art with Imager for Fun
library(tidyverse)
library(imager)
## Following http://dahtah.github.io/imager/ascii_art.html
img_url <-"https://live.staticflickr.com/65535/50916479098_dc9f441e76_c.jpg"
im_orig <- load.image(img_url)
im_orig %>% plot()
@chichacha
chichacha / country-bounding-boxes.py
Created November 22, 2020 20:12 — forked from graydon/country-bounding-boxes.py
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
@chichacha
chichacha / ExperimentWithConvexHull.R
Created March 16, 2020 05:56
Image + K means clustering + Convex Hull
library(magick)
library(imager)
library(tidyverse)
create_pebble_art <- function(img_url,cluster_cnt=500,samp=10000){
img <- image_read(img_url)
## convert image to df
@chichacha
chichacha / chull with nested df
Created March 15, 2020 23:55
Using chull to select points from group to draw smooth curve
library(tidyverse)
library(ggforce)
## Generate Random Points
controls <- data.frame(
x = runif(n=100),
y = rbeta(n=100,shape1=0.8,shape2=0.7)
) %>% mutate(grp=rep(c(1:10),each=10)) %>%
mutate(x=x+grp)%>%
group_by(grp) %>%
@chichacha
chichacha / Norman Bates Characters Graphs
Created November 23, 2019 01:31
Norman Bates Characters
bates <- "https://query.data.world/s/v33quww65lxp73uweh2wldvom4tbe2"
bates <- read_csv(bates)
library(tidygraph)
library(ggraph)
bates_gg <-tbl_graph(edges=bates, directed=F) %>%
@chichacha
chichacha / AbstractMap_UsingOpenStreetMap.r
Created October 6, 2019 20:46
Abstract Map using Open Street Map
library(tidyverse)
library(sf)
library(tidygraph)
library(igraph)
library(units)
library(tmap)
library(osmdata)
@chichacha
chichacha / Random Shapes with sf.r
Last active October 6, 2019 04:45
Random Shape with sf - geometry
rm(list = ls())
library(sf)
library(tidyverse)
library(ggthemes)
## Generate some random data
df <- tibble(
grp = sample(LETTERS[1:18], size=300, replace=T),
@chichacha
chichacha / B-Spline_Fun.R
Last active August 12, 2019 04:27
Simple Example of geom_bspline_closed function in ggforce
library(tidyverse)
library(ggforce)
library(patchwork)
library(ggthemes)
df <- tibble(
t = seq(0,2*pi,length.out=61)
) %>% mutate(idx=row_number(),
m = sqrt((idx%%2)+0.1),
@chichacha
chichacha / create_art_with_words.R
Created August 11, 2019 21:51
Experimentation with ggforce Package
library(tidyverse)
library(tidytext)
library(ggforce)
library(patchwork)
library(ggthemes)
## prep colour palettes
hue_circle <- ggthemes::tableau_color_pal("Hue Circle")(16)