This file contains 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
# 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, |
This file contains 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
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: |
This file contains 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 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") |
This file contains 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
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 |
This file contains 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
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" |
This file contains 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
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, |
This file contains 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
# 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) |
This file contains 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
# 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, |
This file contains 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
# 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, |
This file contains 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
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, |