Skip to content

Instantly share code, notes, and snippets.

View ashgreat's full-sized avatar
💭
Writing a book

Ashwin Malshe ashgreat

💭
Writing a book
View GitHub Profile
@tylermorganwall
tylermorganwall / humanity_globe.R
Created August 17, 2021 14:37
3D Humanity Globe
library(rayshader)
library(rayrender)
popdata = raster::raster("gpw_v4_population_density_rev11_2020_15_min.tif")
population_mat = rayshader:::flipud(raster_to_matrix(popdata))
above1 = population_mat > 1
above5 = population_mat > 5
above10 = population_mat > 10
@elliottmorris
elliottmorris / election_night_live_model.R
Last active January 29, 2024 18:56
A live election-night prediction model using The Economist's pre-election forecast
#' Description
#' This file runs a live election-night forecast based on The Economist's pre-election forecasting model
#' available at projects.economist.com/us-2020-forecast/president.
#' It is resampling model based on https://pkremp.github.io/update_prob.html.
#' This script does not input any real election results! You will have to enter your picks/constraints manually (scroll to the bottom of the script).
#'
#' Licence
#' This software is published by *[The Economist](https://www.economist.com)* under the [MIT licence](https://opensource.org/licenses/MIT). The data generated by *The Economist* are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).
#' The licences include only the data and the software authored by *The Economist*, and do not cover any *Economist* content or third-party data or content made available using the software. More information about licensing, syndication and the copyright of *Economist* content can be fou
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
@IanColdwater
IanColdwater / twittermute.txt
Last active November 17, 2024 02:37
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@eliocamp
eliocamp / pipes_brackets.R
Created July 10, 2019 18:56
pipes vs data.table
library(data.table)
library(magrittr)
library(ggplot2)
set.seed(42)
do_bench <- function(N) {
dt <- suppressWarnings(data.table(x = rnorm(N),
group = letters[1:3]))
pipe <- function() {
dt %>%
@tylermorganwall
tylermorganwall / ramen.R
Last active June 17, 2019 08:47
3D ggplot ramen ratings (#tidytuesday)
library(dplyr)
library(tidyverse)
library(rayshader)
library(ggbeeswarm)
library(forcats)
library(jpeg)
library(grid)
ramen_ratings = readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-06-04/ramen_ratings.csv")
@k5cents
k5cents / FiveThirtyPlot.R
Created March 1, 2019 01:28
A custom ggplot2 theme to mimick the FiveThirtyEight graphics style
library(tidyverse)
theme_538 <- function() {
theme(
plot.title = element_text(face = "bold",
family = "Helvetica",
size = 18,
color = "#222222",
lineheight = 0.5,
vjust = 1),
plot.subtitle = element_text(family = "Helvetica",
---
title: "Using Gensim in R"
author: "Adam Lauretig"
date: "3/17/2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@cszang
cszang / spawn_progressbar.R
Last active February 14, 2023 13:31
A progressbar that fits into a dplyr::mutate -> purrr::map* pipeline
library(rlang)
library(tidyr)
library(dplyr)
library(purrr)
spawn_progressbar <- function(x, .name = .pb, .times = 1) {
.name <- substitute(.name)
n <- nrow(x) * .times
eval(substitute(.name <<- dplyr::progress_estimated(n)))
x
@rCarto
rCarto / mtq.R
Last active August 21, 2023 19:06
library(raster)
library(cartography)
library(sf)
library(SpatialPosition)
mtq <- st_read(system.file("shape/martinique.shp", package="cartography"))
# use WGS84 proj
mtq_latlon <- st_transform(mtq, 4326)
# this call throw an error but seems to work...
getData('SRTM', lon=-61, lat=14)