I am currently working on a project, and so far I have extracted data. Im in the works of visualising some of it. Thats where the issue starts. I have an issue with ggmap density-plotting, especially in areas with smaller amounts of points. I can demonstrate with examples.
Following code is to reproduce the issue:
library(ggmap)
cont <- c(-45,-35)
bins <- 12
higher <- rgb(1,0,0,1)
low <- rgb(0,1,0,0)
gmap <- ggmap(get_googlemap(center = c(cont[1],cont[2]),
zoom = 3,
color = "bw", maptype = "terrain",
style =
"styles=feature:all|element:labels|visibility:off"))
csvf <- read.csv(paste("Filename.csv", sep = ""))
csvf_1st <- select(filter(csvf, bcdate == eventdate &
bctime < "0 days 09:00:00" &bctime > "0 days 03:00:00" &
lat != 0 & lon != 0), c(lat,lon))
c1 <- filter(csvf, as.Date(bcdate) == as.Date(eventdate)+1 &
bctime < "0 days 09:30:00"&bctime > "0 days 03:00:00" &
lat != 0 & lon != 0)
c2 <- filter(csvf, as.Date(bcdate) == as.Date(eventdate)+2 &
bctime < "0 days 09:00:00" &bctime > "0 days 03:00:00"&
lat != 0 & lon != 0)
csvf_2nd <- select(c1, c(lat,lon))
csvf_last <-select(c2, c(lat,lon))
day1 <- gmap + stat_density2d(data = csvf_1st,
mapping = aes(x = lon, y = lat,
fill = (..level..),
alpha = (..level..),
size = 0.0001),
geom = "polygon", bins = bins, na.rm
=TRUE) +
scale_fill_gradient(low = low, high = higher) +
geom_point(data = csvf_1st, mapping = aes(x = lon, y = lat))
day2 <- gmap + stat_density2d(data = csvf_2nd,
mapping = aes(x = lon, y = lat,
fill = (..level..),
alpha = (..level..),
size = 0.0001),
geom = "polygon", bins = bins,
na.rm = TRUE) +
scale_fill_gradient(low = low, high = higher) +
geom_point(data = csvf_2nd ,mapping = aes(x = lon, y = lat))
day3 <- gmap + stat_density2d(data = csvf_last,
mapping = aes(x = lon, y = lat,
fill = (..level..),
alpha = (..level..),
size = 0.0001),
geom = "polygon", bins = bins, na.rm = TRUE) +
scale_fill_gradient(low = low, high = higher) +
geom_point(data = csvf_last ,mapping = aes(x = lon, y = lat))
print(day1)
print(day2)
print(day3)
This code here uses the csv data (hyperlink in next line) for the first day, second day, and third day across the globe, and plots only points which are in south america, and plots a density-mapping on top of it. This link is for the csv file which contains the data points, and should be added to the "Filename.csv", to add the data frame.
Now that you have the data and the plots, this is how they should look:
My question is, why are Day 2 and Day 3 not depicting the correct densities?