From d8438ed4217c41f5685f3ef34881d4729550c1c1 Mon Sep 17 00:00:00 2001 From: "ortrey@gmail.com.noreply.github.com" Date: Fri, 18 Nov 2022 10:20:08 -0500 Subject: [PATCH] Final Answers for Exercise Nine --- Exercise09ans.R | 32 ++++++++++++++++++++++++++++++++ Exercise09answers.R | 10 ++++++++++ 2 files changed, 42 insertions(+) create mode 100644 Exercise09ans.R create mode 100644 Exercise09answers.R diff --git a/Exercise09ans.R b/Exercise09ans.R new file mode 100644 index 0000000..59ab249 --- /dev/null +++ b/Exercise09ans.R @@ -0,0 +1,32 @@ +#Problem 1 +#Find data on any two variable of interest and plot + +soccer<-read.csv("soccer - Sheet1 (2).csv",header=TRUE) +ggplot(soccer, aes(x=Number.of.Matches, y=Avg..Game.Score)) ++xlab("Number of Matches (Mexico)")+ylab("Mexico's Avg Score")+ + geom_point()+geom_smooth(method=lm)+theme_classic() + +#Problem 2 +# Creating a scatter plot of region vs number of observations +#make sure to be on the correct wd--> Exercise09 + +dat<-read.table("data.txt",header=TRUE,stringsAsFactors = FALSE, sep=",") +ggplot(dat, aes(x=region,y=observations))+ geom_jitter(alpha=0.3) ++xlab("Region")+ylab("Observations") + +#creating a bar plot +#still using the same data as before +dat<-read.table("data.txt",header=TRUE,stringsAsFactors = FALSE, sep=",") +ggplot(dat, aes(x=region,y=observations))+ stat_summary(geom="bar",fun="mean")+ + xlab("Region")+ylab("Mean Observation")+theme_classic() + +#The scatter plot and bar do tell me different stories. The scatter plot shows +#the number of observations for each region. East and West both have observations +#that ranges from 0-30 and some outliers. While North is specific to 10-20 and +#South is from 4-6 and 18-30. In contrast, the bar graph shows a mean of obser- +#-vations for each region. They all appear to be around 15. As such, there +# is perhaps some variable that causes makes some observations more spread out +#vs specific in different regions. + + + diff --git a/Exercise09answers.R b/Exercise09answers.R new file mode 100644 index 0000000..d44deb0 --- /dev/null +++ b/Exercise09answers.R @@ -0,0 +1,10 @@ +#Problem 1 +#Find data on any two variable of interest and plot + +soccer<-read.csv("soccer - Sheet1 (2).csv",header=TRUE) +ggplot(soccer, aes(x=Number.of.Matches, y=Avg..Game.Score)) ++xlab("Number of Matches (Mexico)")+ylab("Mexico's Avg Score")+ + geom_point()+geom_smooth(method=lm)+theme_classic() + +#Problem 2 +# Creating a bar plot \ No newline at end of file