/
station-map.Rmd
92 lines (72 loc) · 2.44 KB
/
station-map.Rmd
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
---
title: "A map of the Divvy stations in Chicago"
author: "Peter Carbonetto"
output: html_document
---
<!-- Define defaults shared by all workflowr files. -->
```{r read-chunk, include=FALSE, cache=FALSE}
knitr::read_chunk("chunks.R")
```
<!-- Update knitr chunk options -->
```{r knitr-opts-chunk, include=FALSE}
```
<!-- Insert the date the file was last updated -->
```{r last-updated, echo=FALSE, results='asis'}
```
<!-- Insert the code version (Git commit SHA1) if Git repository
exists and R package git2r is installed -->
```{r code-version, echo=FALSE, results='asis'}
```
In this analysis, I will use the Divvy trip and station data to
generate a map of Chicago.
I begin by loading a few packages, as well as some additional
functions I wrote for this project.
```{r load-packages, message = FALSE}
library(data.table)
library(ggplot2)
source("../code/functions.R")
```
<br>
## Read the data
As [before](first-glance.html), I use function `read.divvy.data` to
read the trip and station data from the CSV files.
```{r load-data}
divvy <- read.divvy.data()
```
<br>
## Get total number of departures by station
I use the trip data to get the total number of departures by station.
From these data, I create a "departures" column.
```{r count-departures}
divvy$stations <-
cbind(divvy$stations,
data.frame(departures = as.vector(table(divvy$trips$from_station_id))))
summary(divvy$stations$departures)
```
<br>
## Create a Divvy stations map
A plot of the Divvy stations by geographic location (latitude and
longitude) traces the outlines of the City of Chicago and the Lake
Michigan shore. Further, the location of the downtown is apparent by
scaling the area of each circle by the number of trips.
The University of Chicago Divvy station is highlighted in red.
```{r create-stations-map, fig.width=6.5, fig.height=7.5}
divvy$stations <-
transform(divvy$stations,
at.uchicago = (name == "University Ave & 57th St"))
ggplot(divvy$stations,aes(x = longitude,
y = latitude,
fill = at.uchicago,
size = sqrt(departures))) +
geom_point(shape = 21,color = "white") +
scale_fill_manual(values = c("darkblue","red")) +
theme_minimal() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
```
<br>
## Session information
This is the version of R and the packages that were used to generate
these results.
```{r session-info}
```