使用R,Php和Mongodb生成热图 [英] Heatmaps generation with R, Php and Mongodb

查看:97
本文介绍了使用R,Php和Mongodb生成热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手.我想使用PHP,MongoDB和R生成热图.我想在世界地图上绘制地理坐标(Lat,Lng).以下是我尝试使用的示例代码.请让我知道如何在静态地图上绘制400万纬度和经度的点.

I'm new to R. i want to generate a heat map using PHP, MongoDB and R. i want to plot geo coordinates(Lat, Lng) on World Map. Below is the sample code i'm trying to use. please let me know how to plot 4 million of lat and lng points on static map.

# 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)

请向我提供适当的解决方案.提前谢谢.

Please provide me the appropriate solution. Thanks In advance.

推荐答案

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万个点在计算上过于昂贵.也许您应该使用数据的子集或样本.

I think 4 million points are too computationally expensive. Maybe you should use a subset or sample from your data.

这篇关于使用R,Php和Mongodb生成热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆