我希望将 ggmap 对象内的视图从默认的 up = true North 旋转到我选择的自定义角度,但在 ggmap 或 get_map 中找不到该选项。目前,我有以下代码:
map1 <- get_map(location=c(-78.872209, 35.050514), zoom = 17, maptype="hybrid")
ggmap(map1)
Run Code Online (Sandbox Code Playgroud)
其产生:

我想旋转图像,以便显示的主要街道(人街)垂直对齐,如下所示(我只是在屏幕捕获软件中手动旋转):

当然,我的目标是仍然具有水平和垂直的 x 和 y 轴作为原始图像,但旋转实际的“视口”。
在旋转(并调整大小)的视口中绘制地图,但以相反方向旋转标签。lon 标签的位置(hjust、vjust)需要稍微调整。如果旋转角度不是太大,调整就可以了。
library(ggmap)
library(grid)
# Get the map
lon <- c(165, 180)
lat <- c(-47.5, -33.5)
map1 <- get_map(location = c(-78.872209, 35.050514), zoom = 17, maptype = "hybrid")
# Angle of rotation
rotate = -67
# Rotate the labels in the opposite direction,
# plus an adjustment of the position of the tick mark labels
map = ggmap(map1) +
theme(axis.text.x = element_text(angle= -rotate,
vjust = 1.1, hjust = ifelse(rotate > 0, 0, 1)),
axis.text.y = element_text(angle = -rotate),
axis.title.y = element_text(angle = -rotate, vjust = 0.5),
axis.title.x = element_text(angle = -rotate))
# Draw the map in a rotated viewport, with its size adjusted
print(map, vp = viewport(width = .7, height = .7, angle = rotate))
Run Code Online (Sandbox Code Playgroud)