This file contains hidden or 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
# R Function to Draw Edward Tufte-style Slopeplots | |
# TODO: | |
## deal with overlapping numeric values: if more than one label falls at a position, offset based on rank() of the subsequent column values for those rows | |
## overlapping rownames (same algorithm as above, but hard code for 1st and 2nd value) | |
slopegraph <- | |
function( | |
df, |
This file contains hidden or 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
pstat <- require(pacman) | |
bostat <- require(BreakoutDetection) | |
if (!pstat) devtools::install_github("trinker/pacman") | |
if (!bostat) devtools::install_github("twitter/BreakoutDetection") | |
p_load(BreakoutDetection, dplyr, XML, qdap) | |
doc <- htmlParse("http://dasonk.com/2014/07/18/Lil-Jon-Analysis/") | |
text <- read.transcript(text = head(sapply(getNodeSet(doc, "//p"), xmlValue), -1)) | |
sents <- sent_detect(text[[1]]) |
This file contains hidden or 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
A function developed by Bryan Goodrich for reading in .docx files: | |
```{r} | |
read_docx <- function (file, skip = 0) { | |
tmp <- tempfile() | |
if (!dir.create(tmp)) | |
stop("Temporary directory could not be established.") | |
unzip(file, exdir = tmp) | |
xmlfile <- file.path(tmp, "word", "document.xml") | |
doc <- XML::xmlTreeParse(xmlfile, useInternalNodes = TRUE) |
This file contains hidden or 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
# Makefile to use knitr for presentations | |
SLIDES := Day1Part1-Introduction.html Day1Part1-session2.html Day1Part1-session3.html Day1Part2-session1.Rmd | |
all: $(SLIDES) | |
clean: | |
rm -rf *.md mplus.* | |
%.html: %.Rmd |
This file contains hidden or 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
function(package, name, qpath, path, ...){ | |
message(sprintf("Attempting to tweak %s...", package)) | |
if (TRUE) message(sprintf("%s has been tweaked!", package)) | |
} |
This file contains hidden or 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
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(babynames, dplyr) | |
lapply(seq(1, 50000, by=35), function(n){ | |
babynames %>% | |
filter(year > 1940 & year < 1980) %>% | |
group_by(name, sex) %>% | |
summarize(n=sum(n))%>% | |
ungroup %>% |
This file contains hidden or 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
if (!require("pacman")) install.packages("pacman"); library(pacman) | |
p_load(dplyr, qdap, qdapRegex, qdapDictionaries, ggplot2, scales) | |
nms <- unlist(qdapRegex::TC(sample(NAMES[[1]], 26))) | |
dat <- data_frame( | |
year = rep(1997:2000, each = length(nms)), | |
observation = rep(nms, length(1997:2000)), | |
score = sample(50:100, length(nms)*length(1997:2000), TRUE) | |
) |
This file contains hidden or 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
L1 <- list( | |
a = c(2, 15, 23, 19, 3, 2, 3, 27, 20, 11, 27, 10, 19, 10, 13, 10), | |
b1 = c(22, 9, 5, 10, 5, 1, 24, 2, 10, 9, 7, 3, 12, 24, 10, 9) | |
) | |
L2 <- list( | |
i = c(16, NA, 17, NA, 2, NA, 2, NA, 10, NA, 15, NA, 6, NA, 9, NA), | |
b2 = c(11, 27, 14, 5, 5, 7, 8, 24, 8, 3, 6, 15, 22, 6, 1, 1) | |
) | |
#L3 <- list( #bad wheel | |
# j = c(3, NA, 8, NA, 10, NA, 14, NA, 11, NA, 8, NA, 12, NA, 11, NA), |
This file contains hidden or 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
load(url("http://dl.dropbox.com/u/61803503/nycounty.RData")) | |
head(ny); head(key) #view the data set from my drop box | |
if (!require("pacman")) install.packages("pacman") | |
p_install_version("ggtree", '1.0.14') | |
p_load(ggplot2, ggtree, dplyr, tidyr, sp, maps, pipeR, grid, XML, qdapRegex, magrittr) | |
getLabelPoint <- function(county) {Polygon(county[c('long', 'lat')])@labpt} | |
df <- map_data('county', 'new york') # NY region county data |
This file contains hidden or 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
#' Convert the output of a topicmodels Latent Dirichlet Allocation to JSON | |
#' for use with LDAvis | |
#' | |
#' @param fitted Output from a topicmodels \code{LDA} model. | |
#' @param corpus Corpus object used to create the document term | |
#' matrix for the \code{LDA} model. This should have been create with | |
#' the tm package's \code{Corpus} function. | |
#' @param doc_term The document term matrix used in the \code{LDA} | |
#' model. This should have been created with the tm package's | |
#' \code{DocumentTermMatrix} function. |
OlderNewer