This homework is due on Feb. 29, 2024 at 11:00pm. Please submit as a pdf file on Canvas.
In this homework, we will work with the ufo_sightings
dataset:
head(ufo_sightings)
The main columns we will use are year
(the year of the
sighting), city
(the city in which the sighting was
reported), and state
(the state in which the sighting was
reported).
Problem 1: (8 pts) Since 1980 (inclusive), what are the top 15 cities that have reported the most UFO sightings? Create a new dataframe to answer the question. No plots are necessary.
(Hint: You can use slice(1:15)
to select the first
fifteen rows in a data frame.)
# your code here
Problem 2: (8 pts)
Next, how has the number of UFO sightings changed for five states since 1970? Please follow these steps:
Your final table should be in long format and have three columns,
year
, state
, and count
. You will
plot this table in Problem 3.
# your code here
Problem 3: (4 pts)
Use the new dataframe you made in Problem 2 and add an appropriate
color scale from the colorspace
package to the plot
below.
your_dataframe_here %>% # use the dataframe from Problem 2 here, and set eval = TRUE in the chunk header
ggplot(aes(x = year, y = count, color = state)) +
geom_line() +
xlab("Year") +
ylab("UFO Sightings (Count)") +
theme_bw()