Skip to content

Instantly share code, notes, and snippets.

View srvanderplas's full-sized avatar

Susan VanderPlas srvanderplas

View GitHub Profile
@srvanderplas
srvanderplas / jqfp.js
Last active June 17, 2023 04:58
Shiny user fingerprint (md5 hash of browser characteristics) and ip address demo. The .R files are in the working directory ("./"), the .js files must be placed in ./www/js/ to be accessible. I wrote the R code, which I will release under the same WTF license as the jqfp.js library is released under.
// Browser fingerprinting is a technique to "mark" anonymous users using JS
// (or other things). To build an "identity" of sorts the browser is queried
// for a list of its plugins, the screen size and several other things, then
// hashes them. The idea is that these bits of information produce an unique
// "fingerprint" of sorts; the more elaborate the list of data points is, the
// more unique this fingerprint becomes. And you wouldn't even need to set a
// cookie to recognize this user when she visits again.
//
// For more information on this topic consult
// [Ars Technica](http://arstechnica.com/tech-policy/news/2010/05/how-your-web-browser-rats-you-out-online.ars)
@srvanderplas
srvanderplas / ThemeProblem.r
Last active January 4, 2016 03:49
Problem with theme() settings and ggplot2 in Rstudio
library(nullabor)
library(ggplot2)
library(plyr)
theme_lineup <- function(base_size = 12, base_family = ""){
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(legend.position="none",
axis.text=element_blank(),
axis.title=element_blank(),
axis.ticks=element_blank())}
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var dirs = json_file.split("/");
dirs.pop(); //if a directory path exists, remove the JSON file from dirs
var element = d3.select(to_select);
// Define functions to render linked interactive plots using d3.
// Another script should define e.g.
// <script>
// var plot = new animint("#plot","path/to/plot.json");
// </script>
// Constructor for animint Object.
var animint = function (to_select, json_file) {
var dirs = json_file.split("/");
dirs.pop(); //if a directory path exists, remove the JSON file from dirs
var element = d3.select(to_select);
@srvanderplas
srvanderplas / server.R
Created January 6, 2015 00:35
Working Example of Unicode Issue with ggplot2 and shiny
library(shiny)
library(ggplot2)
# library(Cairo)
# options(shiny.usecairo=T)
# Define colors and shapes
colors <- c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf")
shapes1 <- c(1,0,3,4,8,5,2,6,-0x25C1, -0x25B7)
shapes2 <- 1:10
@srvanderplas
srvanderplas / Unicode.Rmd
Last active August 29, 2015 14:12
Unicode in ggplot2/shiny/markdown
---
title: "UnicodeTest"
author: "Susan VanderPlas"
date: "01/06/2015"
output: html_document
---
Testing whether it's a browser/rendering issue, which makes no sense to me, but it wouldn't be the strangest error I've come across:
```{r}
@srvanderplas
srvanderplas / animint-line-tooltip.R
Last active August 29, 2015 14:17
Reproducible example that tooltips do not currently work on lines in Animint.
library(animint)
library(ggplot2)
data <- data.frame(x=rep(1:10, times=2), y=c(1:10, 2*(1:10)), type=rep(c("line1","line2"), each=10))
plot1 <-
ggplot() +
geom_line(aes(x=x, y=y, group=type, color=type, tooltip=type), data=data)
# animint2dir(list(lineplot=plot1), out.dir="~/Web/animintexample3", open.browser=T)
@srvanderplas
srvanderplas / Plot fragment hook
Created March 24, 2015 17:59
Knitr plot fragment hook for reveal.js
c0 <- knitr::knit_hooks$get('chunk')
knitr::knit_hooks$set(
list(
chunk=function(x,options){
if(is.null(options$class) & is.null(options$fragIndex)){
c0(x, options)
} else if(is.null(options$fragIndex)) {
classidx <- which(names(options)=="class")
@srvanderplas
srvanderplas / 100 days of weather.R
Last active June 14, 2016 14:18
Demonstrating that 100 days of weather can be used to predict reasonable weather in 3 days
# --- Packages -----------------------------------------------------------------
library(ggplot2) # Plots
library(magrittr) # Pipes
library(dplyr) # Split-Apply-Combine
library(tidyr) # Reshape data
library(stringr) # String manipulation
library(lubridate) # Dates and times
library(readr) # Read in csv/tsv/fwf data
library(readxl) # Read in excel data
# ------------------------------------------------------------------------------
@srvanderplas
srvanderplas / emoji.Rmd
Created August 28, 2018 13:48
Emoji test in Rmarkdown
---
title: "Emoji"
author: "Susan VanderPlas"
date: "8/28/2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```