I have a dataset that looks like this
我有一个看起来像这样的数据集
longitude latitude Magnitude
1 -77.08597 38.7347905 4.742112594
2 -77.08597 38.8081915 4.742112594
3 -77.08597 38.8815925 5.278542493
4 -77.08597 38.9549935 12.270006486
5 -77.08597 39.0283945 4.742112594
6 -77.08597 39.1017955 4.742112594
Is there any way to take these coordinates and magnitude and plot a density map using Google Maps?
有没有办法获取这些坐标和幅度,并使用谷歌地图绘制密度图?
I have tried using the raster
and spatstat
packages to create a map using the coordinates and plotting intensity on it. But I haven't found any solution to plot it on Google Maps.
我已经尝试使用栅格和spatstat包来使用坐标和绘制强度来创建地图。但我没有找到任何解决方案在Google地图上绘制它。
2 个解决方案
#1
1
Use ggmap pacakge of R.
使用R的ggmap pacakge
library(ggmap)
library(ggplot2)
map = get_map(location = c(-77.08597,38.7),source="google",maptype="roadmap",zoom=12)
ggmap(map)+geom_point(data = dat2,aes(x=longitude,y=latitude,size=Magnitude))
You can either scale the the Magnitude vector or increase the zoom
您可以缩放“幅度”矢量或增大缩放
#2
0
I have a Google Maps widget in my googleway
package that uses the Google Maps API, including their heatLayer
.
我的googleway软件包中有一个Google Maps小部件,它使用Google Maps API,包括他们的heatLayer。
To use their API you also need an API key.
要使用他们的API,您还需要一个API密钥。
library(googleway)
## genreate some random data
set.seed(20160907)
df <- data.frame(longitude = runif(10000, min = -78, max = -74),
latitude = runif(10000, min = 37, max = 40),
Magnitude = rexp(10000, 1))
##key <- 'your_api_key'
google_map(data = df, key = key) %>%
add_heatmap(weight = "Magnitude", option_radius = 0.1)
#1
1
Use ggmap pacakge of R.
使用R的ggmap pacakge
library(ggmap)
library(ggplot2)
map = get_map(location = c(-77.08597,38.7),source="google",maptype="roadmap",zoom=12)
ggmap(map)+geom_point(data = dat2,aes(x=longitude,y=latitude,size=Magnitude))
You can either scale the the Magnitude vector or increase the zoom
您可以缩放“幅度”矢量或增大缩放
#2
0
I have a Google Maps widget in my googleway
package that uses the Google Maps API, including their heatLayer
.
我的googleway软件包中有一个Google Maps小部件,它使用Google Maps API,包括他们的heatLayer。
To use their API you also need an API key.
要使用他们的API,您还需要一个API密钥。
library(googleway)
## genreate some random data
set.seed(20160907)
df <- data.frame(longitude = runif(10000, min = -78, max = -74),
latitude = runif(10000, min = 37, max = 40),
Magnitude = rexp(10000, 1))
##key <- 'your_api_key'
google_map(data = df, key = key) %>%
add_heatmap(weight = "Magnitude", option_radius = 0.1)