From bf89f1deede7d939162ebd23e78f5212e632c082 Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Tue, 23 Nov 2021 13:11:56 -0500 Subject: [PATCH 1/3] progress --- Exercise 10 Script.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Exercise 10 Script.R diff --git a/Exercise 10 Script.R b/Exercise 10 Script.R new file mode 100644 index 0000000..901b3cf --- /dev/null +++ b/Exercise 10 Script.R @@ -0,0 +1,13 @@ +# read in data +crime = read.table("crime.txt", header=TRUE, sep="\t", stringsAsFactors=FALSE) + +# use ggplot to produce scatterplot +library(ggplot2) +ggplot(crime, aes(x=Year, y=Crime.Rate)) + + geom_point() + + xlab("Year") + + ylab("Crime Rate (per 100,000 population)") + + ggtitle("Crime Rate Overtime") + + stat_smooth(method="loess") + + theme_classic() + From c28023528bbf62a299c189f504ae8c3736de1aed Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Tue, 23 Nov 2021 13:33:45 -0500 Subject: [PATCH 2/3] turn in homework --- crime.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 crime.txt diff --git a/crime.txt b/crime.txt new file mode 100644 index 0000000..7d69fd5 --- /dev/null +++ b/crime.txt @@ -0,0 +1,27 @@ +Year Crime Rate +1965 26036 +1966 27857 +1967 28846 +1968 33209 +1969 38801 +1970 38018 +1971 41645 +1972 44785 +1973 49433 +1974 52398 +1975 61966 +1976 62207 +1977 58980 +1978 60462 +1979 62037 +1980 56457 +1981 65949 +1982 62126 +1983 60186 +1984 61152 +1985 58770 +1986 62459 +1987 53775 +1988 49216 +1989 47799 + \ No newline at end of file From 79b5e2b4ba51250f447b2682573f3448ae3750e9 Mon Sep 17 00:00:00 2001 From: Emily Chen Date: Tue, 23 Nov 2021 13:35:09 -0500 Subject: [PATCH 3/3] updated submission --- Exercise 10 Script.R | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Exercise 10 Script.R b/Exercise 10 Script.R index 901b3cf..01cfc65 100644 --- a/Exercise 10 Script.R +++ b/Exercise 10 Script.R @@ -1,8 +1,11 @@ +## PROBLEM 1 # read in data crime = read.table("crime.txt", header=TRUE, sep="\t", stringsAsFactors=FALSE) -# use ggplot to produce scatterplot +# load ggplot library(ggplot2) + +# use ggplot to produce scatterplot ggplot(crime, aes(x=Year, y=Crime.Rate)) + geom_point() + xlab("Year") + @@ -11,3 +14,26 @@ ggplot(crime, aes(x=Year, y=Crime.Rate)) + stat_smooth(method="loess") + theme_classic() + +## PROBLEM 2 +# read in data +data = read.table("data.txt", header=TRUE, sep=",", stringsAsFactors = FALSE) + +# use ggplot to produce barplot +ggplot(data, aes(x = region, y = observations)) + + stat_summary(fun = mean, geom = "bar") + + xlab("Region") + + ylab("Average Population") + + theme_classic() + +# produce scatterplot +ggplot(data = data, aes(x = region, y = observations)) + + geom_point() + + geom_jitter() + + theme_classic() + +# the barplot and scatterplot are different because the scatterplot will show +# the distribution of the data, whereas the barplot just reports the average. +# the barplot does not report very precisely. the scatterplot shows that for +# south, the data is very split (bimodal distribution). The barplot does not +# show this. \ No newline at end of file