我目前正在做一个项目,到目前为止我已经提取了数据。我正在对其中的一些进行可视化。这就是问题开始的地方。我对 ggmap 密度绘图有疑问,尤其是在点数较少的区域。我可以举例说明。
以下代码用于重现该问题:
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)
此处的代码使用全球第一天、第二天和第三天的 csv 数据(下一行中的超链接),并仅绘制南美洲的点,并在其顶部绘制密度映射。此链接适用于包含数据点的 csv 文件,应添加到“Filename.csv”中,以添加数据框。
现在您已经有了数据和图表,它们应该是这样的:
我的问题是,为什么第 2 天和第 3 天没有描绘正确的密度?