使用 R、Php 和 Mongodb 生成热图
Heatmaps generation with R, Php and Mongodb
我是 R 的新手。我想使用 PHP、MongoDB 和 R 生成热图。我想在世界地图上绘制地理坐标(纬度、经度)。下面是我尝试使用的示例代码。请告诉我如何在静态地图上绘制 400 万个经纬度点。
# loading the required packages
require(ggplot2)
require(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(78.381270, 78.136352, 77.179950)
lat <- c(17.440229, 10.104529, 28.680417)
df <- as.data.frame(cbind(lon,lat))
# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
maptype = "roadmap", scale = 2)
# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 3, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
请提供合适的解决方案。提前致谢。
ggmap(mapgilbert) +
stat_density2d(data = df, aes(x = lon, y = 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)
我认为 400 万个点的计算量太大了。也许您应该使用数据中的子集或样本。
我是 R 的新手。我想使用 PHP、MongoDB 和 R 生成热图。我想在世界地图上绘制地理坐标(纬度、经度)。下面是我尝试使用的示例代码。请告诉我如何在静态地图上绘制 400 万个经纬度点。
# loading the required packages
require(ggplot2)
require(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(78.381270, 78.136352, 77.179950)
lat <- c(17.440229, 10.104529, 28.680417)
df <- as.data.frame(cbind(lon,lat))
# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
maptype = "roadmap", scale = 2)
# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 3, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
请提供合适的解决方案。提前致谢。
ggmap(mapgilbert) +
stat_density2d(data = df, aes(x = lon, y = 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)
我认为 400 万个点的计算量太大了。也许您应该使用数据中的子集或样本。