# Create weekD variable in GI data set
GI$weekD = as.Date(GI$weekC) # could have used mutate
str(GI$weekD)
## Date[1:21244], format: "2005-02-28" "2005-02-28" "2005-02-28" "2005-02-28" "2005-02-28" ...
# Construct a data set aggregated by week and age category
GI_wa <- GI %>%
group_by(week, ageC) %>%
summarize(count = n())
# Construct a plot to look at weekly GI cases by age category
ggplot(GI_wa, aes(x = week, y = count, color = ageC)) + geom_point()
ggplot(GI_wa, aes(x = week, y = count, shape = ageC)) + geom_point()
ggplot(GI_wa, aes(x = week, y = count, shape = ageC, color = ageC)) + geom_point()
Construct a plot of weekly GI counts by zip3 and ageC.
# Construct data set
GI_za <- GI %>%
group_by(week, zip3, ageC) %>%
summarize(count = n())
# Construct plot of weekly GI counts by zip3 and ageC
ggplot(GI_za, aes(x = week, y = count)) +
geom_point() +
facet_grid(ageC ~ zip3)
Construct a plot for those in zipcode 206xx in 2008.
# Filter the data to zipcode 206xx in 2008
zip206_w <- GI %>%
mutate(year = as.numeric(format(date, "%Y"))) %>%
filter(zip3 == 206,
year == 2008) %>%
group_by(week) %>%
summarize(count = n())
# Construct the plot of weekly GI counts in zipcode 206xx.
ggplot(zip206_w, aes(x = week, y = count)) +
geom_point()