Skip to content

Instantly share code, notes, and snippets.

View uribo's full-sized avatar
🍉
fine

Shinya Uryu uribo

🍉
fine
View GitHub Profile
@tylermorganwall
tylermorganwall / india_historical_map.R
Last active February 25, 2024 18:22
Historical Map of India with 3D elevation
library(raster)
library(rayshader)
#Load QGIS georeference image (see https://www.qgistutorials.com/en/docs/3/georeferencing_basics.html)
testindia = raster::stack("1870_southern-india_modified.tif")
#Set bounding box for final map (cut off edges without data, introduced via reprojection)
india_bb = raster::extent(c(68,92,1,20))
cropped_india = raster::crop(testindia, india_bb)
#Convert to RGB array
pacman::p_load(tidyverse, scales, glue, extrafont, rvest, ggtextures, cowplot, polite)
# Roboto Condensed font (from hrbrmstrthemes or just Google it)
loadfonts()
# web scrape
topg_url <- "https://en.wikipedia.org/wiki/AFC_Asian_Cup_records_and_statistics"
session <- bow(topg_url)
ac_top_scorers <- scrape(session) %>%
@etachov
etachov / nyt_style_buildings.R
Created October 14, 2018 16:23
Making NYT-style building maps with data from Microsoft
library(tidyverse)
library(sf)
library(tigris)
# start by picking a state from https://github.com/Microsoft/USBuildingFootprints
# WARNING: these files can be pretty big. using arizona for its copious subdivisions and reasoanable 83MB.
url_footprint <- "https://usbuildingdata.blob.core.windows.net/usbuildings-v1-1/Arizona.zip"
download.file(url_footprint, "Arizona.zip")
unzip("Arizona.zip")
@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)
library(sf)
library(spatstat)
library(sp)
library(maptools)
library(raster)
library(cartography)
library(SpatialPosition)
## import dataset
feat <- sf::st_read("https://gist.githubusercontent.com/rCarto/747164575e3f216a123c3092d0ce9162/raw/f12390464f255b5f9760c577ab6bf5456cf61a40/iris75.geojson")
@thomasp85
thomasp85 / seal_tracking.R
Last active December 9, 2020 18:23
Animating Elephant Seal movement
library(sf)
library(ggplot2)
library(gganimate)
# Data from personal correspondance
# Collapse all dates to the same year
d$year <- format(d$date, '%Y')
d$stand_time <- as.POSIXct(paste0('2000-', format(d$date, '%m-%d %T')))
@eliocamp
eliocamp / erebus.md
Last active June 8, 2018 09:09
Plot a terrain relief of Erebus volcano with contour lines.
library(data.table)
library(ggplot2)
library(metR)

out.file <- "~/Downloads/erebus_atm_2001_dem_v5.tif"
if (!file.exists(out.file)) {
   # data => https://www.pgc.umn.edu/data/elevation/
   # ~ 90Mb   
   download.file("http://data.pgc.umn.edu/elev/dem/atm/2001/erebus_atm_2001_dem_v5.tif",
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
f, ax = plt.subplots(figsize=(10, 8))
species_list = np.unique(iris.species)
color_list = ['r', 'g', 'b']
data = [np.array(iris[iris.species==s].sepal_length) for s in species_list]
library(tidycensus)
library(tmap)
library(tmaptools)
library(sf)
library(tigris)
library(magick)
library(tidyverse)
options(tigris_use_cache = TRUE)
ctys <- c("Dallas", "Tarrant", "Collin County", "Denton",
require("sf")
require("dplyr")
require("hexbin")
# Linux libertine font "sf", converted to path with Inkscape,
# added points between existing points 2 times, then turned all segments into straight lines.
# Saved as SVG with absolute coordinates (Preferences > SVG Output > Path Data).
# Loaded coords from SVG source code, remove letters from start and end, and replace " " with ","
coords_f <- c(218.1169,163.46992,215.56952,177.96334,213.51976,189.84421,211.82546,200.33884,210.34442,210.67351,208.24728,226.35176,205.51032,243.54066,201.92029,259.27223,197.26391,270.57846,195.45112,272.90665,193.28288,274.70167,190.97247,275.85687,188.73314,276.26564,187.03291,276.03164,185.79476,275.38887,184.84097,274.42619,183.99382,273.23248,182.45947,271.13533,180.24976,269.10927,177.54243,267.58084,174.51519,266.97658,171.25987,267.58973,169.08867,269.18036,167.87718,271.37526,167.501,273.8012,168.44294,277.0032,171.48203,279.79643,176.93817,281.77214,185.13126,282.52154,191.01986,281.80176,196.83737,279.60686,202.29944,