Skip to content

Instantly share code, notes, and snippets.

@mikemahoney218
mikemahoney218 / 20211109.R
Last active November 9, 2021 20:45
Code for my map for the 30 Day Map Challenge on November 09, 2021 ("Monochrome")
library(raster)
library(rayshader)
library(terrainr)
library(sf)
Rainier <- tmaptools::geocode_OSM("Mount Rainier")
Rainier <- st_as_sf(as.data.frame(t(as.data.frame(Rainier$coords))), coords = c("x", "y"), crs = 4326)
zscale <- 5
Rainier <- set_bbox_side_length(
Rainier,
@debruine
debruine / ocrdata.R
Last active October 17, 2021 13:03
Get data from an image
library(dplyr) # for data processing
library(tidyr) # for data processing
library(magick) # for image reading and OCR
library(tesseract) # for OCR
# read image
dataimg <- magick::image_read("https://pbs.twimg.com/media/FBv8P8XXEBgCBvS?format=jpg&name=medium")
# convert image to text
text <- magick::image_ocr(dataimg)
@jcheng5
jcheng5 / README.md
Last active February 2, 2024 10:10
Accepting POST requests from Shiny

Accepting POST requests from Shiny

(This post was motivated by a talk by @jnolis at CascadiaRConf 2021)

Recent versions of Shiny have an undocumented feature for handling POST requests that are not associated with any specific Shiny session. (Note that this functionality is missing our normal level of polish; it's a fairly low-level hook that I needed to make some things possible, but doesn't make anything easy.)

In a nutshell, it works by replacing your traditional ui object with a function(req), and then marking that function with an attribute indicating that it knows how to handle both GET and POST:

library(shiny)
@jhofman
jhofman / changing_ggplot_legends.R
Created June 29, 2017 19:07
Which method do you prefer?
library(tidyverse)
library(forcats)
# The original plot
## This has an ugly legend title, maybe we should remove it and modify the labels
ggplot(mtcars, aes(x = mpg, y = disp, col = as.factor(cyl))) +
geom_point()
# Approach 1: Modify the plot
@veltman
veltman / README.md
Last active July 24, 2022 18:42
Flocking boids
@vasturiano
vasturiano / .blocks.json
Last active July 27, 2023 00:43
3D Force-Directed Graph (ThreeJS)
{"nodes":[{"id":"4062045","user":"mbostock","description":"Force-Directed Graph"},{"id":"1341021","user":"mbostock","description":"Parallel Coordinates"},{"id":"1341281","user":"jasondavies","description":"Parallel Coordinates"},{"id":"b3ff6ae1c120eea654b5","user":"d3noob","description":"Simple d3.js Graph"},{"id":"4963004","user":"calvinmetcalf","description":"Quadtree Madness Round 2"},{"id":"4962892","user":"calvinmetcalf","description":"Quadtree Madness Round 2"},{"id":"4963273","user":"calvinmetcalf","description":"Quadtree Madness Round 2"},{"id":"4967213","user":"calvinmetcalf","description":"Rtree Madness"},{"id":"4060606","user":"mbostock","description":"Choropleth"},{"id":"4686432","user":"dwtkns","description":"Faux-3d Shaded Globe"},{"id":"3757101","user":"mbostock","description":"Lambert Azimuthal Equal-Area"},{"id":"5028304","user":"d3noob","description":"Sankey diagram with horizontal and vertical node movement"},{"id":"4343214","user":"mbostock","description":"Quadtree"},{"id":"1346410","user"
library(tidyverse)
library(ggalt) # devtools::install_github("hrbrmstr/ggalt")
df <- data_frame(
benchmark=c(0.52, 0.57, 0.60, 0.63, 0.64, 0.67),
referrals=c(4.2, 4.5, 4, 4.5, 3.9, 3.6),
year=c(2011, 2012, 2013, 2014, 2015, 2016)
)
# as of 2016-11-07 ggplot2 geom_label() seems to be ignoring the "angle" parameter, hence the non-ideal use of geom_text()
@Fil
Fil / .block
Last active October 17, 2016 14:11
.call(generalpattern)
license: mit
@jirilukavsky
jirilukavsky / generate.R
Last active May 23, 2019 03:28
Make MOT videos
library(ggplot2)
library(animation)
library(circular)
# utility functions for trajectory generation -------------------
# - these function came from motAnalysis package
random.positions <- function(n, xlim = c(-10, +10), ylim = xlim,
dot.radius = 0.5, min.dist = 1) {
pos <- list(
@jfsiii
jfsiii / .block
Last active March 1, 2017 00:10
responsive bar chart
border: no
height: 333
license: CC0-1.0