我正在尝试使用我的lat-log数据来绘制谷歌地图。为此,我尝试下载谷歌地图,然后用它来绘制值。
以下是我尝试下载的方法,但我无法正确理解该功能:
让我们说:
data.lat.long <- data.frame(lat=c(2,3,4,5,6,7,3,7,8,9,2),long=c(3,7,8,9,2,1,2,3,4,5,6),C=c(1,1,1,2,2,1,1,1,1,2,2))
data <- data.lat.long %>% mutate(mean_lat = mean(Latitude)) %>% mutate(mean_long = mean(Longitude))
library(RgoogleMaps)
GetMap(center = c(lat = data$meanlatitude, lon = data$meanlongitude),
size = c(640, 640), destfile = "C:/m/googlemaps/", zoom = 12,
sensor = "true", maptype = c("terrain"),format = c("gif"),
RETURNIMAGE = TRUE, GRAYSCALE = FALSE, NEWMAP = TRUE, SCALE = 1,
API_console_key = NULL, verbose = 0)
我要做的是:我计算了最大和最小纬度点数。我只想下载该区域[从最大纬度到最小纬度&amp;最大经度至最小经度]。
答案 0 :(得分:1)
ggmap
的基本用法:
library(dplyr)
library(ggmap)
library(ggthemes)
data.lat.long <- data.frame(lat=c(2,3,4,5,6,7,3,7,8,9,2),
long=c(3,7,8,9,2,1,2,3,4,5,6),
C=c(1,1,1,2,2,1,1,1,1,2,2))
data.lat.long %>%
mutate(mean_lat = mean(lat),
mean_long = mean(long)) -> dat
# use variables in your own code, pref with a bounding box vs centroid
# as that makes it possible to not rely on the zoom param
loc <- get_map(c(lon=4.545455, lat=5.090909), zoom=4)
gg <- ggmap(loc)
gg <- gg + geom_point(data=data.lat.long,
aes(x=long, y=lat),
size=3, color="black")
gg <- gg + theme_map()
gg