Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ChicagoMarathon2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Miles run,HR
1,163
2,172
3,174
4,177
5,179
6,178
7,180
8,179
9,180
10,181
11,179
12,175
13,181
14,189
15,190
16,180
17,175
18,182
19,194
20,195
21,192
22,187
23,167
24,163
25,160
26,167
26.1,174
37 changes: 37 additions & 0 deletions Exercise10.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Exercise 10 - Analysis and plotting

# Loading the packages
library(ggplot2)
library(cowplot)

# First problem
chithonHR = read.csv("ChicagoMarathon2.csv", header=TRUE, stringsAsFactors=FALSE)
ggplot(data=chithonHR, aes(x=Miles.run,y=HR)) +
geom_point() +
theme_classic() +
stat_smooth(method="loess") +
xlab("Miles Run") +
ylab("Heart Rate") +
ggtitle("Chicago Marathon")

# Second problem
popdata = read.table("data.txt", header=TRUE, sep=",", stringsAsFactors=FALSE)
# Show a barplot of the means of the four populations
popbarplot = ggplot(data=popdata, aes(x=region,y=observations)) +
stat_summary(fun=mean, geom="bar") +
xlab("Region") +
ylab("Population Mean") +
theme_classic()
# Show a scatterplot of all of the observations
popscatterplot = ggplot(data=popdata, aes(x=region,y=observations)) +
geom_point() + geom_jitter(alpha=0.1) +
xlab("Region") +
ylab("Observation") +
theme_classic()
# Display plots together for comparison
popcomparison = plot_grid(popbarplot, popscatterplot)
popcomparison
# These two plots do give very different representations of the data.
# The bar plot demonstrates that the population means of each region are similar.
# The scatter plot shows how there are different ranges of observations.
# While the means are similar, the distribution of observations is very different.