Skip to content

Instantly share code, notes, and snippets.

View mrnosal's full-sized avatar

Mike Nosal mrnosal

  • MITRE Corporation
  • Bedford, MA
View GitHub Profile
library(tidycensus)
library(mapdeck)
library(sf)
options(tigris_use_cache = TRUE)
tract_median_age <- get_acs(
geography = "tract",
variables = "B01002_001",
state = c(state.abb, "DC", "PR"),
geometry = TRUE
library(dplyr)
library(slider)
library(lubridate)
library(tsibbledata)
# Google, Apple, Facebook, Amazon stock
gafa_stock <- as_tibble(gafa_stock)
gafa_stock <- select(gafa_stock, Symbol, Date, Close, Volume)
head(gafa_stock, 2)
@jennybc
jennybc / 2020-03-29_sane-legend.R
Created March 30, 2020 05:21
Make the legend order = data order, with forcats::fct_reorder2()
library(tidyverse)
library(patchwork)
dat_wide <- tibble(
x = 1:3,
top = c(4.5, 4, 5.5),
middle = c(4, 4.75, 5),
bottom = c(3.5, 3.75, 4.5)
)
@malcolmbarrett
malcolmbarrett / move_slides_to_web.R
Last active April 2, 2019 10:28
Move R Markdown HTML slides to Blogdown and Push to Web
# install.packages(c("here", "fs", "stringr", "purrr", "git2r"))
# to add invisibly in your R profile, open with usethis::edit_r_profile()
# then define it in an environment, e.g.
# .env <- new.env()
# .env$move_slides_to_web <- {function definition}
move_slides_to_web <- function(folder = NULL, index = NULL) {
if (is.null(folder)) {
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
@walkerke
walkerke / app.R
Last active September 12, 2022 13:27
library(shiny)
library(spdep)
library(leaflet)
library(RColorBrewer)
atx <- readRDS('travis.rds')
atx$id <- 1:nrow(atx)
atx2 <- atx[!is.na(atx$income), ]
@rmoff
rmoff / 00.README.md
Last active December 1, 2021 23:45
RMarkdown - repeating child block with changing variable value

When you use knit_expand it appears that the inclusion of the Rmd is done on the first pass, and then the complete document evaluated. This means that a Rmd block referenced in loop with knit_expand will only evaluate changing variables at their last value.

This can be worked around by passing the literal value of the variable at the time of the knit_expand with {{var}} syntax.

This is documented in the knitr_expand docs, but less clear (to an R noob like me) for embedded documents rather than strings.

@doowb
doowb / Gruntfile.js
Created May 24, 2014 01:11
Loading page data from json files and dynamically building page objects to pass into Assemble options.
'use strict';
var _ = require('lodash');
var path = require('path');
module.exports = function(grunt) {
// load the recipe template from the desired path
var recipeTemplate = grunt.file.read('./src/templates/pages/recipe.hbs');
// expand the data files and loop over each filepath
@tompazourek
tompazourek / feathericons.less
Last active February 2, 2019 23:34
Feather icons (http://colebemis.com/feather/) for Bootstrap
@charset "UTF-8";
@font-face {
font-family: "feather";
src: ~"url('@{icon-font-path}feather-webfont.eot')";
src: ~"url('@{icon-font-path}feather-webfont.eot?#iefix') format('embedded-opentype')",
~"url('@{icon-font-path}feather-webfont.woff') format('woff')",
~"url('@{icon-font-path}feather-webfont.ttf') format('truetype')",
~"url('@{icon-font-path}feather-webfont.svg#featherregular') format('svg')";
font-weight: normal;
@Sumbera
Sumbera / L.CanvasOverlay.js
Last active February 3, 2023 09:47
Leaflet Canvas Overlay
/*
UPDATE July 2016 , moved and updated to here: https://github.com/Sumbera/gLayers.Leaflet
Generic Canvas Overlay for leaflet,
Stanislav Sumbera, April , 2014
- added userDrawFunc that is called when Canvas need to be redrawn
- added few useful params fro userDrawFunc callback
- fixed resize map bug
inspired & portions taken from : https://github.com/Leaflet/Leaflet.heat