ggmap扩展缩放或边界 [英] ggmap extended zoom or boundaries
问题描述
我正在尝试解决以下问题。
我用ggplot2来绘制一个岛屿的地图:
$ p $ island $ get_map(location = c(lon = - ) (a,b,c,c,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b) = 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 =纬度),data = data,size = 4, color =#ff0000)
islandMap + RL
如何确保地图与使用zoom = 14一样大,所有点都在图中(加上一个边距)和卫星图像? 解决方案
使用我从
I am trying to fix the following problem. I use ggplot2 to plot a map of an island:
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
Coordinates of the RL points:
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))
)
Now the problem is that when I use zoom = 13 the island is too small in the plot and when I use zoom = 14 it is perfectly centered. But when I plot the RL points, two get cut off because its too much to the East and the other one too much to the West. I looked some solutions up like the following one, using a boundary box. However, I am bound to using satellite imagery, so bound to Google, which doesn't support the boundary box solution.
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
How can I make sure that the map is as big as using zoom = 14, all the points are within the plot (plus a margin around this) and satellite imagery?
Using my answer from this question, I did the following. You may want to get a map with zoom = 13, and then you want to trim the map with scale_x_continuous()
and 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))
这篇关于ggmap扩展缩放或边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!