Quick Question
In the previous video, our heatmap was plotting squares out in the water, which seems a little strange. We can fix this by removing the observations from our data frame that have Freq = 0.
Take a subset of LatLonCounts, only keeping the observations for which Freq > 0, and call it LatLonCounts2.
Redo the heatmap from the end of Video 5, using LatLonCounts2 instead of LatLonCounts. You should no longer see any squares out in the water, or in any areas where there were no motor vehicle thefts.
How many observations did we remove?
Exercise 1
Numerical Response
Explanation
You can take a subset of LatLonCounts, only keeping the observations for which Freq > 0 with the following command:
LatLonCounts2 = subset(LatLonCounts, Freq > 0)
Then, you can generate the new heatmap with the following command:
ggmap(chicago) + geom_tile(data=LatLonCounts2, aes(x = Long, y = Lat, alpha=Freq), fill=“red”)
The number of observations in LatLonCounts2 is 686, and the number of observations in LatLonCounts is 1638. These numbers can be found by using nrow or str.
CheckShow Answer