Skip to content

Instantly share code, notes, and snippets.

@bhive01
bhive01 / code.R
Created January 13, 2014 15:03 — forked from patilv/code.R
library(rCharts)
library(plyr)
library(reshape2)
library(scales)
findata=read.csv("https://raw.github.com/patilv/rChartsTutorials/master/findata.csv")
# These are data regarding NCAA athletic department expenses at public universities. Please see the blog post where these charts were originally used
# regarding more details on the origins of these data.: http://analyticsandvisualization.blogspot.com/2013/10/subsidies-revenues-and-expenses-of-ncaa.html
findata=findata[,-c(1:2)] # removing first dummy column - the csv quirk - and second column on Rank.
require(tidyr)
require(dplyr)
#require(ggplot2)
# from: https://twitter.com/JennyBryan/status/646047312830050304
separate(data.frame(x = "howdy"), x, into = 1:6, sep = "(?!^)")
#works with more than one word
separate(data.frame(x = c("howdy", "snake")), x, into = 1:6, sep = "(?!^)")
## short version
require(ggplot2)
graphdata <- structure(list(X12136 = c(79L, 15L, 60L, 33L, 53L, 89L, 21L,
25L, 83L, 3L, 64L, 47L, 39L, 1L, 99L, 69L, 9L, 59L, 8L, 10L,
23L, 74L, 65L, 81L, 42L, 79L, 15L, 60L, 33L, 53L, 89L, 21L, 25L,
83L, 3L, 64L, 47L, 39L, 1L, 99L, 69L, 9L, 59L, 8L, 10L, 23L,
74L, 65L, 81L, 42L, 79L, 15L, 60L, 33L, 53L, 89L, 21L, 25L, 83L,
3L), pheno = structure(list(Condition = structure(c(2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
@bhive01
bhive01 / 0_circle.jpg
Last active January 12, 2016 21:22
Matisse Colors
0_circle.jpg
@bhive01
bhive01 / README.md
Last active January 29, 2016 17:46 — forked from ramnathv/README.md

Livecoding D3 in RStudio

This is a proof-of-concept on how one can use RStudio to livecode D3 visualizations.

Usage

You will need to install a couple of packages before getting started

devtools::install_github("yihui/servr")
require(dplyr)
# input data frame
df1 <- data.frame(trait=rep(1:10, 4), Trait.Code = rep(LETTERS[1:4], each = 10), Alpha_Value= rep(c(NA, "1", NA, "Alphastuff"), each = 10), Number_Value = rep(c(3, NA, 6, NA), each = 10), stringsAsFactors= FALSE)
df1 %>%
mutate(n=row_number()) %>% #add index for later join
filter(!is.na(Alpha_Value), Alpha_Value != "NULL") %>% # Alpha_Value != NULL or NA
group_by(Trait.Code) %>% #group for mutate
mutate(Converted_Value = ifelse(any(is.na(as.numeric(.$Alpha_Value))), NA, as.numeric(Alpha_Value))) %>%
require(ggplot2)
require(dplyr)
require(plotly)
test <- data.frame(year = rep(2001:2016, each=10), group= rep(LETTERS[1:16], times = 10), count = runif(160))
gg <- ggplot(test, aes(x=year, y = count, group = group, colour = group)) +
geom_point() +
geom_line()
gg
L.shell.Day5 a.shell.Day5 b.shell.Day5 Hex.shell.Day5 L.shell.Day1 a.shell.Day1 b.shell.Day1 Hex.shell.Day1
61.1824499603039 -22.076387665463 32.2221171514149 #8A9F68 59.1700367857259 -22.0471225002006 34.9234624183896 #859758
56.8621418223068 -24.97288907957 42.0601786964881 #778D3B 51.5169668478454 -23.9252046480325 36.6068073530096 #627A37
62.7257035685657 -22.9733681151521 35.8083291448731 #8AA164 57.7975941354515 -22.202011261358 35.4614903698262 #809651
59.9427072331491 -23.4729626916318 34.455617994546 #809957 55.2358856160348 -21.9162837108123 35.5743258652009 #778C49
63.6548194655096 -24.6867708185501 44.698102412673 #8DA34C 54.0763291124911 -21.8893308495491 35.6211872004396 #748946
67.5740105523698 -23.8259047306477 45.808160158852 #9AAD54 58.3355995894783 -24.1634822371787 37.4696438729551 #7C954D
73.2291440290129 -21.7287032147082 38.4157268985132 #AABB72 61.9082465991772 -20.7769111456906 31.9351191059027 #899D61
58.871658635331 -23.2615793573258 37.1729800997476 #7F964F 57.398673319426 -22.7656
@bhive01
bhive01 / fileIOinR.R
Last active May 20, 2016 19:56 — forked from rmflight/feather_input.R
feather benchmarking
library(devtools)
library(iotools)
library(R.utils)
library(feather) # install_github("wesm/feather/R")
library(microbenchmark)
library(data.table)
library(readr)
library(ggplot2)
library(plotly)
library(dplyr)
library(tidyr)
no_col <- max(count.fields("https://gist.githubusercontent.com/bhive01/ad5f2f51b02aed0ccfbd50ee3bb8dd68/raw/e0a66e51c88da13861bfa9f624aef5bb62cbfb32/fruitshape.txt", sep = ","))
cukeshape <- read.table("https://gist.githubusercontent.com/bhive01/ad5f2f51b02aed0ccfbd50ee3bb8dd68/raw/e0a66e51c88da13861bfa9f624aef5bb62cbfb32/fruitshape.txt",sep=",",fill=TRUE,col.names=1:no_col)
tcukeshape <- as.data.frame(t(cukeshape))
tcukeshape %>%
gather(., fruit, width) %>%