I have a dataset with the ff columns: (1) latitude of locations; (2) longitude; (3) population_count; (4) sample_count; (5) sample_perc (sample/ pop).
I need to visualise the sample_perc (col 5) over the ggmap output of the city as a heatmap. The problems I'm encountering are:
- Not all coordinates in the map are relevant, and hence do not have data
- Heatmap (geom_density) uses entries (rows) in the data and can't do aggregate (as far as I know)
Code:
amsmap <- get_map(location="amsterdam", zoom=14)
ggmap(amsmap) +
geom_density2d(data = dummy$sample_perc,
aes(x =request_lng, y = request_lat), size = 0.3) +
stat_density2d(data = dummy$sample_perc,
aes(x = request_lng, y = request_lat, fill = ..level..,
alpha = ..level..), size = 0.01, bins = 16, geom = "polygon") +
scale_fill_gradient(low = "green", high = "red") +
scale_alpha(range = c(0, 0.3), guide = FALSE)
error: ggplot2 doesn't know how to deal with data of class factor
How can I successfully do this? Help please.