Skip to content

Instantly share code, notes, and snippets.

Shawn Mollie Taylor mollietaylor

Block or report user

Report or block mollietaylor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View dateFormats.R
# importing dates:
dates <- c("05/27/84", "07/07/05")
betterDates <- as.Date(dates,
format = "%m/%d/%y") # here you put the format your dates are currently in
# it will output the ISO standard dates (%Y-%m-%d)
# or:
dates <- c("May 27 1984", "July 7 2005")
betterDates <- as.Date(dates,
@mollietaylor
mollietaylor / log.R
Created Jun 23, 2013
Plot Weekly or Monthly Totals in R
View log.R
library(ggplot2)
library(scales)
# load data:
log <- data.frame(Date = c("2013/05/25","2013/05/28","2013/05/31","2013/06/01","2013/06/02","2013/06/05","2013/06/07"),
Quantity = c(9,1,15,4,5,17,18))
log
str(log)
# convert date variable from factor to date format:
View nationalParksArea.R
# load up area shape file:
library(maptools)
area <- readShapePoly("ne_10m_parks_and_protected_lands_area.shp")
# # or file.choose:
# area <- readShapePoly(file.choose())
library(RColorBrewer)
colors <- brewer.pal(9, "BuGn")
@mollietaylor
mollietaylor / callan.R
Last active Jan 19, 2016
Elevation Profiles in R
View callan.R
gps <- read.csv("callan.csv",
header = TRUE)
# calculate moving average: (this section is optional)
library(TTR)
movingN <- 5 # define the n for the moving average calculations
gps$Altitude <- gps$Altitude * 3.281 # convert m to ft
gps$SMA <- SMA(gps$Altitude,
n = movingN)
gps <- gps[movingN:length(gps$SMA), ] # remove first n-1 points
@mollietaylor
mollietaylor / elwyn.R
Last active Apr 16, 2016
Basemaps in R Using get_map
View elwyn.R
gps <- read.csv("elwyn.csv",
header = TRUE)
library(ggmap)
mapImageData <- get_map(location = c(lon = mean(gps$Longitude),
lat = 33.824),
color = "color", # or bw
source = "google",
maptype = "satellite",
# api_key = "your_api_key", # only needed for source = "cloudmade"
@mollietaylor
mollietaylor / customlegend.R
Last active Feb 24, 2016
Using Line Segments to Compare Values in R
View customlegend.R
library(RColorBrewer)
colors = brewer.pal(8, "Dark2")
library(ggplot2)
data <- as.data.frame(USPersonalExpenditure) # data from package datasets
data$Category <- as.character(rownames(USPersonalExpenditure)) # this makes things simpler later
ggplot(data,
aes(x = Expenditure,
@mollietaylor
mollietaylor / file.R
Created Jan 7, 2013
Storing a Function in a Separate File in R
View file.R
# calling the functions
# this is the file where we will call the functions in fun.R and times.R
times <- dget("times.R")
times(-4:4, 2)
source("fun.R")
mult(-4:4, 2)
@mollietaylor
mollietaylor / gini.R
Created Jan 2, 2013
Calculating a Gini Coefficients for a Number of Locales at Once in R
View gini.R
# generate random data:
city <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
income <- sample(1:100000,
100,
replace = TRUE)
cities <- data.frame(city, income)
# graph our data:
library(ggplot2)
ggplot(cities,
@mollietaylor
mollietaylor / stacked.R
Created Dec 11, 2012
Stacked Bar Charts in R
View stacked.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,
View Mapping GPS Tracks in R
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,
You can’t perform that action at this time.