This is an additional theme for ggplot2
that generates an inverse black and white color scheme.
ggplot(mtcars, aes(wt, mpg)) + geom_point()
# Add theme_black()
ggplot(mtcars, aes(wt, mpg)) + geom_point(color = "white") + theme_black()
library(foreign) | |
mytest.alldata <- list() | |
mytest.csvfile <- c() | |
mytest.dtafile <- c() | |
mytest.filelist <- list.files(path="data",pattern="*sav",recursive=FALSE,full.names=T) | |
for (number in 1:length(mytest.filelist)) { | |
mytest.alldata[[number]] <- read.spss(mytest.filelist[number],to.data.frame = TRUE) | |
mytest.csvfile[number] <- gsub("data/|.sav","",mytest.filelist[number]) | |
mytest.csvfile[number] <- paste(mytest.csvfile[number],".csv",sep="") | |
mytest.dtafile[number] <- gsub("csv","dta",mytest.csvfile[number]) |
library(NLP) | |
library(openNLP) | |
# credit due to http://stackoverflow.com/questions/30995232/how-to-use-opennlp-to-get-pos-tags-in-r | |
## SET "data.dir" to a directory containing text files. It's not designed for nested directories. | |
data.dir <- "data/texts/" | |
## SET "saveas.file" to the destination directory. Resulting files have an "n" prepended to the file name, but it may be useful to save to a separate directory. | |
saveas.file <- "data/texts-n/" |
library(tidyverse) | |
library(tidytext) | |
library(reshape2) | |
library(wordVectors) | |
##### Modeling a Corpus ##### | |
# This process for preparing and modeling the corpus is adapted from Women Writers Project's template_word2vec.Rmd | |
# These adaptations should allow for for preservation of modeling settings to aid in replicability. | |
# After training the model, recall its setting parameters by exploring the object's attributes. |
base_beg <- "https://en.wikipedia.org/wiki/Category:" | |
base_end <- "th-century_novels" | |
get_cat_pages <- function(){ | |
categories <<- data.frame(century=c(), | |
nation=c(), | |
url=c(), | |
stringsAsFactors = FALSE) | |
for (century in centuries){ | |
cat_url <- paste0(base_beg,century,base_end) |
library(stylo) | |
library(ggplot2) | |
library(dendextend) | |
# Load with this line: devtools::source_gist("79cd732fb9e6a4f1dd14f1caaac4ee2d") | |
# Use df <- stylo() to save frequency results | |
# Then use stylo2gg(df) to visualize principal components | |
# Use stylo2gg(df, viz="hc") to show hierarchical clusters without rerunning stylo | |
stylo2gg <- function(df, |
remotes::install_github("kjhealy/covdata") | |
library(covdata) | |
library(dplyr) | |
library(ggplot2) | |
library(ggrepel) | |
library(tidyr) | |
covus_wide <- covus %>% | |
select(date, state, measure, count) %>% | |
pivot_wider(id_cols = c(date, state), |
\newrobustcmd*{\mkcomprangezero}{% | |
\begingroup | |
\@ifstar | |
{\blx@range@aux\blx@comprange@ii} | |
{\blx@range@aux\blx@comprange@i}} | |
\def\blx@comprange@i[#1][#2]#3{% | |
\let\blx@tempa\@empty | |
\protected\def\blx@range@out@value{\appto\blx@tempa}% | |
\def\blx@range@out@item@process{#2}% | |
\let\blx@range@out@delim\blx@range@out@value |
# To prepare it for use in documentation, import a .bib file, strip Bibdesk's extra fields and additions, and enclose each entry with code compatible with Latex's {listings} package. | |
library(dplyr) | |
library(stringr) | |
library(readr) | |
# 0. Set relative file path for the bibfile | |
# setwd() | |
# 1. read the bib file as a vector of lines |
\usepackage{listings} | |
\usepackage{xcolor} | |
\let\oldaddbibresource\addbibresource | |
\renewcommand{\addbibresource}[1]{% | |
\oldaddbibresource{#1}% | |
\expandafter\newcommand\csname thebibfile\endcsname{#1}% | |
} | |
% \makeatletter |