Skip to content

Instantly share code, notes, and snippets.

View mollietaylor's full-sized avatar

Shawn Mollie Taylor mollietaylor

View GitHub Profile
@mollietaylor
mollietaylor / sectors.R
Created September 7, 2012 22:31
Map of prominent patent sectors of 50 largest U.S. cities in R
sectors <- read.table("sectors.csv", header=TRUE, sep=",")
library(maps)
library(RColorBrewer)
library(classInt)
names(sectors)
plotvar <- sectors$secnum #change this line to change data
plotclr <- brewer.pal(5,"Set1")
class <- classIntervals(plotvar, 5, 'pretty')#or pretty
colcode <- findColours(class, plotclr)
map("state", ylim=range(50, 22), col=8)
@mollietaylor
mollietaylor / conventions.csv
Created September 8, 2012 03:09
Simple word cloud example in R
wordper25k democrats republicans
millionaires 7 0
arithmetic 3 0
equal pay 6 0
level playing field 2 0
bin laden 5 0
auto 18 1
fair 13 1
middle class 47 7
forward 33 6
@mollietaylor
mollietaylor / histdens.R
Created September 9, 2012 17:33
Histogram + Density Plot Combo in R
png("beaverhist.png")
layout(matrix(c(1:2), 2, 1,
byrow = TRUE))
hist(beaver1$temp, # histogram
col = "peachpuff", # column color
border = "black",
prob = TRUE, # show densities instead of frequencies
xlim = c(36,38.5),
xlab = "temp",
main = "Beaver #1")
@mollietaylor
mollietaylor / histdens2.R
Created September 23, 2012 03:17
Adding Measures of Central Tendency to Histograms in R
png("beaverhistextra.png")
layout(matrix(c(1:2), 2, 1,
byrow = TRUE))
hist(beaver1$temp, # histogram
col = "peachpuff", # column color
border = "black",
prob = TRUE, # show densities instead of frequencies
xlim = c(36,38.5),
ylim = c(0,3),
xlab = "Temperature",
@mollietaylor
mollietaylor / reality.R
Created October 5, 2012 03:10
Random Name Generator in R
# recreating realitytvgenerator.com
# dictionary:
# define our two vectors with the names we'd like to use
first <- c("Fear", "Frontier", "Nanny", "Job", "Yard", "Airport", "Half Pint", "Commando", "Fast Food", "Basketball", "Bachelorette", "Diva", "Baggage", "College", "Octane", "Clean", "Sister", "Army", "Drama", "Backyard", "Pirate", "Shark", "Project", "Model", "Survival", "Justice", "Mom", "New York", "Jersey", "Ax", "Warrior", "Ancient", "Pawn", "Throttle", "The Great American", "Knight", "American", "Outback", "Celebrity", "Air", "Restaurant", "Bachelor", "Family", "Royal", "Surf", "Ulitmate", "Date", "Operation", "Fish Tank", "Logging", "Hollywood", "Amateur", "Craft", "Mystery", "Intervention", "Dog", "Human", "Rock", "Ice Road", "Shipping", "Modern", "Crocodile", "Farm", "Amish", "Single", "Tool", "Boot Camp", "Pioneer", "Kid", "Action", "Bounty", "Paradise", "Mega", "Love", "Style", "Teen", "Pop", "Wedding", "An American", "Treasure", "Myth", "Empire", "Motorway", "Room", "Casino", "Comedy", "Unde
@mollietaylor
mollietaylor / palettes-in-R.R
Created October 24, 2012 03:19
Palettes in R
palette()
# it's fine for your vector to include a mixture of hex triplets and R color names:
colors <- c("#A7A7A7",
"dodgerblue",
"firebrick",
"forestgreen",
"gold")
hist(discoveries,
col = colors)
@mollietaylor
mollietaylor / subfigures.tex
Created October 31, 2012 04:08
Subfigures in LaTeX
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
@mollietaylor
mollietaylor / sort.R
Created November 13, 2012 03:56
Sorting Within Lattice Graphics in R
library(lattice)
colors = c("#1B9E77", "#D95F02", "#7570B3")
dotplot(rownames(mtcars) ~ mpg,
data = mtcars,
col = colors[1],
pch = 1)
dotplot(reorder(rownames(mtcars), cyl) ~ mpg,
data = mtcars,
gps <- read.csv("out.csv",
header = TRUE)
library(ggmap)
mapImageData <- get_googlemap(center = c(lon = median(gps$Longitude), lat = median(gps$Latitude)),
zoom = 11,
# size = c(500, 500),
maptype = c("terrain"))
ggmap(mapImageData,
@mollietaylor
mollietaylor / stacked.R
Created December 11, 2012 23:55
Stacked Bar Charts in R
# cite: http://stat.ethz.ch/R-manual/R-patched/library/stats/html/reshape.html
# cite: http://www.cs.grinnell.edu/~rebelsky/Courses/MAT115/2008S/R/stacked-bar-graphs.html
# cite: http://www.harding.edu/fmccown/r/#barcharts
library(RColorBrewer)
sequential <- brewer.pal(6, "BuGn")
Loblolly[1:10,]
wide <- reshape(Loblolly,