diff --git a/ChicagoMarathon2.csv b/ChicagoMarathon2.csv new file mode 100644 index 0000000..83c781e --- /dev/null +++ b/ChicagoMarathon2.csv @@ -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 \ No newline at end of file diff --git a/Exercise10.R b/Exercise10.R new file mode 100644 index 0000000..b9dc4cc --- /dev/null +++ b/Exercise10.R @@ -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. \ No newline at end of file