Skip to content

Instantly share code, notes, and snippets.

@LCHansson
LCHansson / 0-ggplot-format-snippets.R
Last active March 9, 2017 06:18
ggplot format snippets
##############################################################################
## ##
## FORMATSNIPPETS.R ##
## ggplot format snippets ##
## ##
##############################################################################
#### LABELS ####
# Hide labels
@benmarwick
benmarwick / battleship_CAseriation.R
Last active July 23, 2024 18:25
ggbattleship - battleship curves with R and ggplot2, and some other methods
# From http://cainarchaeology.weebly.com/r-package-for-seriation-via-ca.html
library(CAseriation)
data("perfect_seriation")
#loads the sample dataset
check.ca.plot(perfect_seriation,1,2)
#plot the Correspondence Analysis scatterplot of the first 2 dimensions in order #to inspect data structure (e.g., seeking for the horseshoe effect)
sort.table(perfect_seriation,1)
@timelyportfolio
timelyportfolio / tables are like cockroaches.rmd
Created April 3, 2013 19:28
document the journey to recreate an old table in HTML using R
Tables Are Like Cockroaches
========================================================
As much as I would like to completely replace all tables with beautiful, intuitive, and interactive charts, tables like cockroaches cannot be eliminated. Based on this very [interesting discussion on the Perceptual Edge forum](http://sfew.websitetoolbox.com/post/Old-or-oldest-data-table-5702966) with source [Exploring the Origins of Tables for Information Visualization](http://api.viglink.com/api/click?format=go&key=ccc2217bc2b75c4bdf5f7e57267f0464&loc=http%3A%2F%2Fsfew.websitetoolbox.com%2Fpost%2FOld-or-oldest-data-table-5702966&v=1&libid=1365001395530&out=http%3A%2F%2Fcsis.pace.edu%2F~marchese%2FPapers%2FIV11%2FMarchese_IV%252711.pdf&ref=http%3A%2F%2Fwww.google.com%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3D%26esrc%3Ds%26frm%3D1%26source%3Dweb%26cd%3D2%26ved%3D0CDoQFjAB%26url%3Dhttp%253A%252F%252Fsfew.websitetoolbox.com%252Fpost%252FOld-or-oldest-data-table-5702966%26ei%3DpERcUcvxPImY9QTKi4GwCg%26usg%3DAFQjCNFppNIFLhtMVC3W9Xklbffh8lAm
#### prepare workspace
rm(list = ls(all.names = TRUE))
gc()
#### get data into the R session
# set R's working directory
setwd("C:/Users/Marwick/Downloads/JSTOR") # change this to where you downloaded the data!
# Get zip file of CSVs from JSTOR and unzip
# this may take a few minutes...
unzip("2013.4.20.FxFmBVYd.zip")
@jiffyclub
jiffyclub / swc-vm.pp
Last active December 16, 2015 23:09
Puppet manifest for a VM suitable for Software Carpentry boot camps.
package { "dkms":
ensure => latest,
}
package { "chromium-browser":
ensure => latest,
}
package { "emacs":
ensure => latest,
@benmarwick
benmarwick / DTM_disk_storage.R
Created June 2, 2013 08:22
Storing a DocumentTermMatrix on disk (ie. out of memory) using the filehash and ff packages in R
# test of storing a DTM on disk...
# reproducible data
library(tm)
data(crude)
dtm <- DocumentTermMatrix(crude)
library(filehash)
dbCreate("testDB")
db <- dbInit("testDB")
@stephenturner
stephenturner / .Rprofile.r
Last active January 3, 2025 12:36
My .Rprofile
## See http://gettinggeneticsdone.blogspot.com/2013/06/customize-rprofile.html
## Load packages
library(BiocInstaller)
## Don't show those silly significanct stars
options(show.signif.stars=FALSE)
## Do you want to automatically convert strings to factor variables in a data.frame?
## WARNING!!! This makes your code less portable/reproducible.
@christophergandrud
christophergandrud / d3SimpleNetwork.R
Last active March 7, 2017 07:28
An R function for creating simple D3 javascript directed network graphs.
#' An R function for creating simple D3 javascript directed network graphs.
#'
#' d3SimpleNetwork creates simple D3 javascript network graphs.
#'
#' @param data a data frame object with three columns. The first two are the names of the linked units. The third records an edge value. (Currently the third column doesn't affect the graph.)
#' @param Source character string naming the network source variable in the data frame. If \code{Source = NULL} then the first column of the data frame is treated as the source.
#' @param Target character string naming the network target variable in the data frame. If \code{Target = NULL} then the second column of the data frame is treated as the target.
#' @param height numeric height for the network graph's frame area.
#' @param width numeric width for the network graph's frame area.
#' @param file a character string of the file name to save the resulting graph. If a file name is given a standalone webpage is created, i.e. with a header and footer. If \code{file = NULL} then
@Thell
Thell / Exmple.Rmd
Created June 20, 2013 23:59
R markdown to illustrate creation of in-document referencing for chunks, sections, pages, and such.
```{r setup, echo=FALSE, results='hide'}
chunkref <- local({
function(chunklabel) {
sprintf('[%s](#%s)', chunklabel, chunklabel )
}
})
secref <- local({
function(seclabel) {
sprintf('[%s](#%s)', seclabel, seclabel )
#check for and/or install dependencies
need<-c("RCurl","ggplot2","gridExtra","reshape2")
for(i in 1:length(need)){
if(require(need[i], character.only = TRUE)==FALSE){ install.packages(need[i]);library(need[i], character.only = TRUE)} else { library(need[i],character.only = TRUE)}
}
if(require(pcaMethods)==FALSE){
need<-c('Rcpp', 'rJava',
'Matrix', 'cluster', 'foreign', 'lattice', 'mgcv', 'survival')
for(i in 1:length(need)){