forked from katiejolly/met-council-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
394 lines (394 loc) · 13.9 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
bookdown:::serve_book()
bookdown:::serve_book()
library(knitr)
library(tidyverse)
library(fivethirtyeight)
library(rmarkdown)
library(knitr)
library(tidyverse)
library(fivethirtyeight)
library(rmarkdown)
knitr::include_graphics("images/03-01-newproject.png")
knitr::include_graphics("images/03-02-newproject.png")
bookdown:::serve_book()
if <- 3+2
install.packages("bookdown"
)
bookdown:::serve_book()
install.packages(
"fivethirtyeight"
)
bookdown:::serve_book()
fivethirtyeight::tv_hurricanes_by_network
data(tv_hurricanes_by_network)
data("tv_hurricanes_by_network")
View(tv_hurricanes_by_network)
View(tv_hurricanes)
tripdata_201906 <- read_csv(unzip("https://s3.amazonaws.com/niceride-data/201906-niceride-tripdata.csv.zip"))
tripdata_201906 <- unzip("https://s3.amazonaws.com/niceride-data/201906-niceride-tripdata.csv.zip")
download.file("https://s3.amazonaws.com/niceride-data/201906-niceride-tripdata.csv.zip",temp, mode="wb")
temp <- tempfile()
download.file("https://s3.amazonaws.com/niceride-data/201906-niceride-tripdata.csv.zip",temp, mode="wb")
unzip(temp, "tripdata_201906.csv")
unzip(temp, "201906-niceride-tripdata.csv.zip")
unzip(temp, "201906-niceride-tripdata.csv")
unzip(temp, "2001906-niceride-tripdata.csv")
dd <- read_csv("2001906-niceride-tripdata.csv")
View(dd)
temp <- tempfile()
download.file("https://s3.amazonaws.com/niceride-data/Nice_ride_data_2017_season.zip",temp, mode="wb")
unzip(temp, "Nice_ride_trip_history_2017_season.csv")
Nice_ride_trip_history_2017_season <- read_csv("Nice_ride_trip_history_2017_season.csv")
download.file("https://s3.amazonaws.com/niceride-data/Nice_ride_data_2017_season.zip",temp, mode="wb")
unzip(temp, "Nice_ride_trip_history_2017_season.csv")
temp
unzip(temp, "Nice_ride_data_2017_season.csv")
unzip(temp, "Nice_ride_data_2017_season.zip")
temp <- tempfile()
temp <- tempfile()
download.file("https://s3.amazonaws.com/niceride-data/Nice_ride_data_2017_season.zip",temp, mode="wb")
temp
unzip(temp, "Nice_ride_trip_history_2017_season.csv")
niceride_2017 <- read_csv("data_large/Nice_ride_trip_history_2017_season.csv")
View(niceride_2017)
bookdown:::serve_book()
library(metcouncilR)
data("nice_ride_2018") # niceride dataset
table(nice_ride_2018$usertype)
View(nice_ride_2018)
help("nice_ride_2018")
hist(nice_ride_2018$tripduration)
barplot(table(nice_ride_2018$usertype))
barplot(table(nice_ride_2018$usertype), main = "User Type")
barplot(table(nice_ride_2018$bike_type), main = "Bike Type")
ggplot(nice_ride_2018) # set up our plotting area and axes
ggplot(nice_ride_2018, aes(x = usertype)) # set up our plotting area
ggplot(nice_ride_2018, aes(x = usertype)) +
geom_bar() # add the geoms
ggplot(nice_ride_2018, aes(x = usertype)) +
geom_bar() +
labs(title = "User Types") # add a title
knitr::include_graphics("images/rstudiocloud.png")
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
bookdown::render_book("index.Rmd", "bookdown::epub_book")
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
library(tinytex)
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
tinytex::install_tinytex()
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
bookdown::render_book("index.Rmd", "bookdown::pdf_book")
bookdown:::serve_book()
ggplot(nice_ride_2018) # set up our plotting area
ggplot(nice_ride_2018, aes(x = tripduration)) # set up our axes
ggplot(nice_ride_2018, aes(x = tripduration)) +
geom_histogram() # add the geoms
60 * 5
ggplot(nice_ride_2018, aes(x = tripduration)) +
geom_histogram(binwidth = 300) # add the geoms
summary(nice_ride_2018$tripduration)
summary(nice_ride_2018$tripduration)
11136253/60
185604.2 / 60
3093.403 /24
11720 /60
13435/60
70247 /60
1170.783 /60
5 * 24
5 * 24 * 60 * 60
67785 / 60
67785 / 60 / 60
5 * 60 * 60
nice_ride_2018 <- filter(nice_ride_2018, tripduration <= 18000)
data("nice_ride_2018")
nice_ride_2018_2 <- filter(nice_ride_2018, tripduration <= 18000)
ggplot(nice_ride_2018_2, aes(x = tripduration)) +
geom_histogram() # add the geoms
ggplot(nice_ride_2018, aes(x = usertype)) +
geom_bar() +
labs(title = "User Types", x = "User Type", y = "Trips") # add a title
ggplot(nice_ride_2018_2, aes(x = tripduration)) +
geom_histogram() + # add the geoms
labs(title = "Durations of trips under 5 hours (in seconds)", x = "Duration (seconds)", y = "Trips")
data("nice_ride_2018")
View(nice_ride_2018)
library(metcouncilR)
data("nice_ride_2018") # niceride dataset
help("nice_ride_2018")
hist(nice_ride_2018$start_month)
ggplot(nice_ride_2018, aes(x = start_month)) # set up our axes
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram() # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bindwith = 1) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bindwith = 2) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram() # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 24) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 20) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 12) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 0) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 5) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 7) # add the geoms
ggplot(nice_ride_2018, aes(x = start_month)) +
geom_histogram(bins = 8) # add the geoms
hist(nice_ride_2018$start_hour)
hist(nice_ride_2018$tripduration)
data("nice_ride_2018") # niceride dataset
help("nice_ride_2018")
library(metcouncilR)
data("nice_ride_2018") # niceride dataset
help("nice_ride_2018")
install_github("katiejolly/metcouncilR")
install_github("katiejolly/metcouncilR", force = TRUE)
library(metcouncilR)
data("nice_ride_2018") # niceride dataset
hist(nice_ride_2018$tripduration)
ggplot(nice_ride_2018, aes(x = tripduration)) # set up our axes
ggplot(nice_ride_2018, aes(x = tripduration)) +
geom_histogram() # add the geoms and the total number of geoms that you want
ggplot(nice_ride_2018, aes(x = tripduration)) +
geom_histogram() + # add the geoms
labs(title = "Durations of trips under 5 hours (in seconds)", x = "Duration (seconds)", y = "Trips")
ggplot(nice_ride_2018, aes(x = birth_year)) +
geom_bar() +
labs(title = "Reported birth year of riders", x = "Year", y = "Trips") # add a title
sum(nice_ride_2018$birth_year == 60)
sum(nice_ride_2018$birth_year == 1970)
sum(nice_ride_2018$birth_year == 1971)
sum(nice_ride_2018$birth_year == 1972)
sum(nice_ride_2018$birth_year == 1970)
sum(nice_ride_2018$birth_year == 1969)
sum(nice_ride_2018$birth_year == 1968)
sum(nice_ride_2018$birth_year == 1969)
ggplot(nice_ride_2018, aes(x = start_day)) + geom_bar(fill = "cyan4")
ggplot(nice_ride_2018, aes(x = start_day)) +
geom_bar(fill = "cyan4") +
theme_minimal() +
labs("What days did people use niceride in 2018?", x = "Day of the week", y = "Trips", caption = "Source: Niceride MN")
ggplot(nice_ride_2018, aes(x = start_day)) +
geom_bar(fill = "cyan4") +
theme_minimal() +
labs("What days did people use niceride in 2018?", x = "Day of the week", y = "Trips", caption = "Source: Niceride MN")
ggplot(nice_ride_2018, aes(x = start_day)) +
geom_bar(fill = "cyan4") +
theme_minimal() +
labs(title = "What days did people use niceride in 2018?", x = "Day of the week", y = "Trips", caption = "Source: Niceride MN")
ggplot(nice_ride_2018, aes(x = start_day)) +
geom_bar(fill = "cyan4") +
theme_minimal() +
labs(title = "What days did people use niceride in 2018? Weekends are a favorite.", x = "Day of the week", y = "Trips", caption = "Source: Niceride MN")
bookdown:::serve_book()
saturday_trips <- filter(nice_ride_2018, start_day == "Sat")
dim(saturday_trips) # check that you have these dimensions
after_12 <- filter(nice_ride_2018, end_hour > 12)
dim(after_12)
saturday_after_12 <- filter(nice_ride_2018, end_hour > 12 & start_day == "Sat")
weekend_trips <- filter(nice_ride_2018, start_day == "Sat" | start_day == "Sun")
weekendFri_trips <- filter(nice_ride_2018, start_day %in% c("Sat", "Sun", "Fri"))
weekendFri_trips <- filter(nice_ride_2018, start_day == "Sat" | start_day == "Sun" | start_day == "Fri")
weekendFri_trips <- filter(nice_ride_2018, start_day == "Sat" | start_day == "Sun" | start_day == "Fri")
dim(weekendFri_trips)
weekendFri_trips <- filter(nice_ride_2018, start_day %in% c("Sat", "Sun", "Fri"))
dim(weekendFri_trips)
print(vec)
vec <- c("Katie", "Dunn", "Jolly") # a vector of the 3 parts of my name
print(vec)
vec + 1
vec <- c(1, 4, 9, 25) # a vector of squares
vec + 1
sqrt(vec)
vec <- c(1, 4, 9, 16) # a vector of squares
vec + 1
sqrt(vec)
library(tidyverse)
library(sf)
library(leaflet)
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count() %>%
top_n(n, 10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count() %>%
top_n(10, n) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
top_n
?top_n
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count() %>%
top_n(10, n)
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count() %>%
top_n(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun")) %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
filter(nice_ride_2018, start_station_name == "NULL")
nulls <- filter(nice_ride_2018, start_station_name == "NULL")
View(nulls)
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & biketbike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme(axis.text = element_text(angle = 80))
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme(axis.text = element_text(angle = 60, vjust = 1))
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme(axis.text = element_text(angle = 60, hjust = 1))
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_histogram()
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_histogram(binwidth = 1)
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_histogram(binwidth = 1) +
facet_wrap(~start_day)
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_histogram(binwidth = 1, color = "white") +
facet_wrap(~start_day)
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_histogram(binwidth = 1, color = "white") +
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_density(binwidth = 1, color = "white") +
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_density() +
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
?geom_density
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_density(adjust = 2) +
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_density(adjust = 1.5) +
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
ggplot(nice_ride_2018, aes(x = start_hour)) +
geom_density(adjust = 1.5) + # the adjust argument just makes the plots a little smoother
facet_wrap(~start_day) + # lay out the plots by the weekday
theme_minimal()
bookdown:::serve_book()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme(axis.text = element_text(angle = 60, hjust = 1)) +
theme_minimal()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
theme_minimal()
nice_ride_2018 %>%
filter(start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme_minimal() +
theme(axis.text = element_text(angle = 60, hjust = 1))
nice_ride_2018 %>%
filter(!start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(start_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme_minimal() +
theme(axis.text = element_text(angle = 60, hjust = 1))
nice_ride_2018 %>%
filter(!start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(end_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = start_station_name, y = n)) +
geom_col() +
theme_minimal() +
theme(axis.text = element_text(angle = 60, hjust = 1))
nice_ride_2018 %>%
filter(!start_day %in% c("Sat", "Sun") & bike_type == "Classic") %>%
group_by(end_station_name) %>%
count() %>%
arrange(desc(n)) %>%
head(10) %>%
ggplot(aes(x = end_station_name, y = n)) +
geom_col() +
theme_minimal() +
theme(axis.text = element_text(angle = 60, hjust = 1))