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
44 changes: 44 additions & 0 deletions Exercise09_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#Assumes working directory is set to Exercise09 directory

library(ggplot2)
library(cowplot)

#1

#loads txt file
q1_data <- read.table("q1_data.txt", header=TRUE, sep="\t")

#generates scatterplot with trendline
ggplot(q1_data, aes(x = Height, y = Weight)) +
geom_point() +
xlab("Height (ft)") +
ylab("Weight (lbs)") +
stat_smooth(method="lm") +
theme_classic()

#2

#loads txt file
q2_data <- read.table("data.txt", header=TRUE, sep=",")

#generates barplot showing the mean observations for each region
ggplot(q2_data, aes(x=region,y=observations, fill=region)) +
stat_summary(fun=mean, geom= "bar") +
xlab("Region") +
ylab("Average Observations") +
theme_classic()

#generates scatterplot showing observations for each region
ggplot(q2_data, aes(x=region,y=observations, color=region)) +
geom_jitter() +
xlab("Region") +
ylab("Observations") +
theme_classic()

#The scatterplot and barplot do tell different stories. The barplot makes it seem like
#the observations are the same in all regions. However, looking at the scatterplot,
#we can see that the distribution of observations varies quite a bit between regions.
#For example, in the east there is a wide range of observations. In the north, the range
#of observations is small, yet the average is the same as the other regions. In the south,
#there seems to be two clusters of groups, a high and low obervation cluster. The west
#also showed a wide distribution of values.
34 changes: 34 additions & 0 deletions q1_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Height Weight
6.1 203
4.8 122
5.4 145
5.2 135
5.7 162
5.8 164
6.3 220
5.5 151
5.5 157
5.2 123
5.1 118
6.2 199
6.5 241
5.6 157
5.7 170
4.8 111
4.9 118
5.2 130
5.4 147
5.5 153
4.8 109
4.9 117
5 124
5.1 125
5.2 137
5.3 135
5.4 151
5.5 158
5.6 165
5.7 169
5.8 173
5.9 183
6 190