使用 R 在 google 地图上应用坐标点
Applying coordinates points on google map using R
首先感谢大家的宝贵时间....
我想让你知道我是 R 的新手
我正在尝试使用 R 绘制我的坐标。我已经尝试过遵循不同的 post 函数,其中一个我将在下面添加它,我有坐标点的文件覆盖了我想在 [= 中绘制它们的世界33=]卫星地图?
我也有 API 密钥,但我不知道如何在代码中添加它?
require(ggplot2)
require(ggmap)
require(maps)
require(mapproj)
require(mapdata)
require(rgeos)
require(maptools)
require(sp)
require(raster)
require(rgdal)
require(dismo)
require(tmp)
####
swf1 <- read.csv("D:/jamal project/swf1.csv",header=TRUE)
head(swf1)
Lon Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847
#i try using ggmap’s make_bbox function
swfp <- make_bbox(lon = swf$lon, lat = swf$lat, f = .1)
swfp
###i got this messg
Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
4: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
> swfp
left bottom right top
-Inf -Inf Inf Inf
现在我不知道如何添加我的点的问题,我想要每个区域一种颜色。
有人可以帮助我继续吗?
我尝试过的另一个选择是:
# loading the required packages
library(ggplot2)
library(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(-38.31,-35.5)
lat <- c(40.96, 37.5)
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 = "satellite", 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 =
5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
当我 运行 我得到了这个
download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 错误:
无法打开 URL 'http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false'
另外: 警告信息:
在 download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 中:
无法打开 URL“http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false”:HTTP 状态为“403 禁止访问”
帮忙求坐标文件HERE试试...
谢谢
这是一个使用 library(googleway)
的解决方案
library(googleway)
set_key( "API_KEY" )
swf1 <- read.table(text='
Lon Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847')
## you've asked for colours and sizes, so I'm making some random values which you can use in the plot
swf1$region <- sample(c("a","b"), size = nrow(swf1), replace = T)
swf1$size <- sample(50000:100000, size = nrow(swf1))
google_map() %>%
add_circles(
data = swf1, lon = "Lon", lat = "Lat", fill_colour = "region", radius = "size"
)
要获取卫星视图,请按地图上的 'satellite' 按钮
首先感谢大家的宝贵时间.... 我想让你知道我是 R 的新手 我正在尝试使用 R 绘制我的坐标。我已经尝试过遵循不同的 post 函数,其中一个我将在下面添加它,我有坐标点的文件覆盖了我想在 [= 中绘制它们的世界33=]卫星地图? 我也有 API 密钥,但我不知道如何在代码中添加它?
require(ggplot2)
require(ggmap)
require(maps)
require(mapproj)
require(mapdata)
require(rgeos)
require(maptools)
require(sp)
require(raster)
require(rgdal)
require(dismo)
require(tmp)
####
swf1 <- read.csv("D:/jamal project/swf1.csv",header=TRUE)
head(swf1)
Lon Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847
#i try using ggmap’s make_bbox function
swfp <- make_bbox(lon = swf$lon, lat = swf$lat, f = .1)
swfp
###i got this messg
Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
4: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
> swfp
left bottom right top
-Inf -Inf Inf Inf
现在我不知道如何添加我的点的问题,我想要每个区域一种颜色。
有人可以帮助我继续吗?
我尝试过的另一个选择是:
# loading the required packages
library(ggplot2)
library(ggmap)
# creating a sample data.frame with your lat/lon points
lon <- c(-38.31,-35.5)
lat <- c(40.96, 37.5)
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 = "satellite", 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 =
5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)
当我 运行 我得到了这个 download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 错误: 无法打开 URL 'http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false' 另外: 警告信息: 在 download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 中: 无法打开 URL“http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false”:HTTP 状态为“403 禁止访问”
帮忙求坐标文件HERE试试... 谢谢
这是一个使用 library(googleway)
library(googleway)
set_key( "API_KEY" )
swf1 <- read.table(text='
Lon Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847')
## you've asked for colours and sizes, so I'm making some random values which you can use in the plot
swf1$region <- sample(c("a","b"), size = nrow(swf1), replace = T)
swf1$size <- sample(50000:100000, size = nrow(swf1))
google_map() %>%
add_circles(
data = swf1, lon = "Lon", lat = "Lat", fill_colour = "region", radius = "size"
)
要获取卫星视图,请按地图上的 'satellite' 按钮