This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################### | |
# Example data | |
###################################### | |
testdata<-replicate(10, rpois(100, 20)) | |
########################################### | |
# This function tells us how far we have to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Set Environment Variables | |
TEXINPUTS="C:\\" #Path to tex file in Windows | |
Sys.setenv(TEXINPUTS="C:\\~", BIBINPUTS=TEXINPUTS,BSTINPUTS=TEXINPUTS) | |
#Path to texfiles in Windows, set BIB files and BST files the same | |
#Run before clicking "Compile PDF" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################ | |
## Title: Make an Animated Heart in R | |
## Author: Jared Knowles | |
## Date: May 5th, 2012 | |
############################################################ | |
# Make heart curve | |
t<-seq(-100,100,length.out=1000) # Order | |
x<-16*sin(t)^3 # Create the Xs from a formula | |
y<-(13*cos(t))-(5*cos(2*t))-(2*cos(3*t))-(cos(4*t)) # Create Ys from a formula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Made by Jared Knowles | |
# Not necessarily going to work for scripts outside of the Public folder | |
# Not recommended for production use | |
# myurl must be a character string with the full public link of the script file | |
# Problem--we can't use URL shorteners | |
dropbox_source<-function(myurl){ | |
s<-str_extract(myurl,"[/][a-z][/]\\d+[/][a-z]*.*") | |
new_url<-paste("http://dl.dropbox.com",s,sep="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####################################### | |
## FRPL MAP ## | |
## Create a series of maps plotting ## | |
## FRPL proportions from Wisconsin ## | |
## Publicly available data ## | |
###################################### | |
# Version 0.7 | |
# Date: 08/21/2012 | |
# Author: Jared E. Knowles, Policy Research Advisor DPI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate lotto numbers | |
# Avoid a split pot | |
# Author: Jared Knowles | |
# Date: 11/26/2012 | |
# All numbers are equally likely to be selected to win in PowerBall, | |
# but what fun is winning if we have to share the pot? | |
# Therefore, we will only select numbers that minimize our | |
# likelihood of sharing the pot. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# data from : http://is-r.tumblr.com/post/35266021903/five-thirty-hate | |
election.data <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/election2012.csv") | |
shinyServer(function(input,output){ | |
output$voteplot<-reactivePlot(function(){ | |
Mode <- function(X) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(scales) | |
# obs | |
# length | |
dat<-data.frame(dist=c("all","under20","twenties","thirties","forties","over50"), | |
att=c(266,6,79,74,85,22), | |
made=c(230,6,76,67,66,15)) | |
dat$per<-dat$made/dat$att | |
dat$distprob<-dat$att/266 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggplot2) | |
library(eeptools) | |
library(plyr) | |
# Sampling examples | |
probs<-c(.05,.15,.4,.4) | |
samprobs<-c(.4,.4,.15,.05) | |
############### | |
# Convenience functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyServer(function(input,output){ | |
output$distPlot<-reactivePlot(function(){ | |
dist<-rnorm(input$obs) | |
p<-qplot(dist,binwidth=0.1)+geom_vline(xintercept=mean(dist))+theme_dpi() | |
p<-p+coord_cartesian(xlim=c(-4,4))+geom_vline(xintercept=median(dist),color=I("red")) | |
print(p) | |
}) |
OlderNewer