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(OIdata) | |
data(birds) | |
library(ggplot2) | |
levels(birds$effect) <- gsub(" ", "\n", levels(birds$effect)) | |
ggplot(birds, | |
aes(x = effect, | |
y = speed)) + | |
geom_boxplot() + | |
coord_flip() |
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
str(ChickWeight$Diet) | |
table(ChickWeight$Diet) | |
ols <- lm(weight ~ Time + Diet, | |
data = ChickWeight) | |
summary(ols) | |
ChickWeight$Diet <- relevel(ChickWeight$Diet, | |
ref = 4) |
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
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 |
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
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", |
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
# 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
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
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
City | State | Latitude | Longitude | |
---|---|---|---|---|
San Francisco | CA | 37.7782251 | -122.4424955 | |
New York | NY | 40.7142691 | -74.0059729 | |
Los Angeles | CA | 34.0522342 | -118.2436849 | |
Chicago | IL | 41.850033 | -87.6500523 | |
Dallas | TX | 32.7830556 | -96.8066667 | |
Columbus | GA | 32.4609764 | -84.9877094 | |
Columbus | OH | 39.9611755 | -82.9987942 |