Skip to content

Instantly share code, notes, and snippets.

View raffdoc's full-sized avatar

Rafik Margaryan raffdoc

View GitHub Profile
@dsparks
dsparks / voronoi_raster.R
Created October 30, 2012 15:41
Image Manipulation, Part 3
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("ReadImages", "reshape", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Image URL:
allImageURLs <- c("http://media.charlesleifer.com/blog/photos/thumbnails/akira_940x700.jpg",
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/402px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg",
"http://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Official_portrait_of_Barack_Obama.jpg/441px-Official_portrait_of_Barack_Obama.jpg",
"http://cache.boston.com/universal/site_graphics/blogs/bigpicture/obama_11_05/obama22_16604051.jpg",
@wch
wch / heightweight.csv
Created November 7, 2012 20:46
Shiny height-weight example
sex ageYear ageMonth heightIn weightLb
f 11.91667 143 56.3 85
f 12.91667 155 62.3 105
f 12.75 153 63.3 108
f 13.41667 161 59 92
f 15.91667 191 62.5 112.5
f 14.25 171 62.5 112
f 15.41667 185 59 104
f 11.83333 142 56.5 69
f 13.33333 160 62 94.5
@timelyportfolio
timelyportfolio / server.r
Created November 9, 2012 15:30
Example to Test Parameters on Moving Average System
#almost entirely based on the 02_text and 03_mpg examples provided by RStudio Shiny
#all credit belongs to them
if (!require(PerformanceAnalytics)) {
stop("This app requires the PerformanceAnalytics package. To install it, run 'install.packages(\"PerformanceAnalytics\")'.\n")
}
if (!require(quantmod)) {
stop("This app requires the quantmod package. To install it, run 'install.packages(\"quantmod\")'.\n")
@cdesante
cdesante / plottext1.r
Created November 14, 2012 04:57
plottext1
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
library(ggplot2)
text.plots <- data.frame(
SUPP = c (rep(c( "Control", "Vitamin C", "Orange Juice" ), each = 1500)) ,
DOSE = rep(rep(c( "I", "II", "III" ), each=500), 3),
LENGTH = c(rnorm(500, 4, 2),
rnorm(500, 7, 1.2),
@mages
mages / Setting_lattice_options.R
Created November 30, 2012 21:58
Setting lattice colour and legend options
library(MASS)
library(lattice)
## Plot the claims frequency against age group by engine size and district
barchart(Claims/Holders ~ Age | Group, groups=District,
data=Insurance, origin=0, auto.key=TRUE)
barchart(Claims/Holders ~ Age | Group, groups=District,
data=Insurance,main="Claims frequency",
auto.key=list(space="top", columns=4,
title="District", cex.title=1))
@psychemedia
psychemedia / global.R
Last active January 1, 2022 15:13
f1 laptime explorer - Shiny - ergast API
library(RJSONIO)
library(plyr)
#racechart
#Helper functions
getNum=function(x){as.numeric(as.character(x))}
timeInS=function(tStr){
x=unlist(strsplit(tStr,':'))
tS=60*getNum(x[1])+getNum(x[2])
@dsparks
dsparks / Amelia_example.R
Created December 6, 2012 14:40
Multiple imputation for missing data
doInstall <- TRUE
toInstall <- c("Amelia", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents,
head(ANES) # remove some non-helpful variables
with(ANES, plot(jitter(pid7), jitter(ideo7)))
@dsparks
dsparks / sna_example.R
Created December 11, 2012 13:34
Flag similarity network
# Drawing a scatter plot of raster images
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("png", "sna")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Go to https://www.gosquared.com/resources/2400-flags, download the ZIP,
# and put the 64 x 64 files into a directory of your choosing.
# Then setwd() to that directory:
setwd("C:/Dropbox/isDotR_Files/flagIcons")
@dsparks
dsparks / tm_example.R
Created December 11, 2012 16:43
Denver debate analysis I
rm(list = ls())
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("zoo", "tm", "ggplot2", "Snowball")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# From: http://www.cnn.com/2012/10/03/politics/debate-transcript/index.html
Transcript <- readLines("https://raw.github.com/dsparks/Test_image/master/Denver_Debate_Transcript.txt")
head(Transcript, 20)
@christophergandrud
christophergandrud / source_GitHubData.R
Last active March 31, 2020 04:58
A function for downloading data stored on GitHub in a plain-text format (e.g. CSV, TSV) into R. The function loads the data as a data frame. For more details see: http://christophergandrud.blogspot.com/2013/01/sourcegithubdata-simple-function-for.html.
#####################
# R function for downloading plain-text data from GitHub
# Christopher Gandrud
# 7 January 2013
#####################
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package
source_GitHubData <-function(url, sep = ",", header = TRUE)
{