gpt4 book ai didi

r - ggmap 扩展缩放或边界

转载 作者:行者123 更新时间:2023-12-04 23:42:11 24 4
gpt4 key购买 nike

我正在尝试解决以下问题。
我使用 ggplot2 绘制岛屿 map :

island = get_map(location = c(lon = -63.247593, lat = 17.631598), zoom = 14, maptype = "satellite")
islandMap = ggmap(island, extent = "panel", legend = "bottomright")
RL = geom_point(aes(x = longitude, y = latitude), data = data, size = 4, color = "#ff0000")
islandMap + RL

RL 点的坐标:
data = data.frame(
ID = as.numeric(c(1:8)),
longitude = as.numeric(c(-63.27462, -63.26499, -63.25658, -63.2519, -63.2311, -63.2175, -63.23623, -63.25958)),
latitude = as.numeric(c(17.6328, 17.64614, 17.64755, 17.64632, 17.64888, 17.63113, 17.61252, 17.62463))
)

现在的问题是,当我使用 zoom = 13 时,该岛在图中太小,而当我使用 zoom = 14 时,它完全居中。但是当我绘制 RL 点时,有两个被截断,因为它对东方太多,另一个对西方太多。我使用边界框查找了一些解决方案,如下所示。但是,我必须使用卫星图像,因此必须使用不支持边界框解决方案的 Google。
lon = data$longitude
lat = data$latitude
box = make_bbox(lon, lat, f = 0.1)
island = get_map(location = box, zoom = 14, source = "osm")
islandMap = ggmap(island, extent = "panel", legend = "bottomright")
RL = geom_point(aes(x = longitude, y = latitude), data = data, size = 4, color = "#ff0000")
islandMap + RL

如何确保 map 与使用缩放 = 14 一样大,所有点都在绘图内(加上周围的边缘)和卫星图像?

最佳答案

使用我的回答 this question ,我做了以下。你可能想得到一张缩放 = 13 的 map ,然后你想用 scale_x_continuous() 修剪 map 。和 scale_y_continuous() .

library(ggmap)
library(ggplot2)

island = get_map(location = c(lon = -63.247593, lat = 17.631598), zoom = 13, maptype = "satellite")


RL <- read.table(text = "1 17.6328 -63.27462
2 17.64614 -63.26499
3 17.64755 -63.25658
4 17.64632 -63.2519
5 17.64888 -63.2311
6 17.63113 -63.2175
7 17.61252 -63.23623
8 17.62463 -63.25958", header = F)

RL <- setNames(RL, c("ID", "Latitude", "Longitude"))


ggmap(island, extent = "panel", legend = "bottomright") +
geom_point(aes(x = Longitude, y = Latitude), data = RL, size = 4, color = "#ff0000") +
scale_x_continuous(limits = c(-63.280, -63.20), expand = c(0, 0)) +
scale_y_continuous(limits = c(17.60, 17.66), expand = c(0, 0))

enter image description here

关于r - ggmap 扩展缩放或边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34158767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com