你如何在ggmap中旋转地图的视图? [英] How do you rotate the view of a map in ggmap?
问题描述
我正在将ggmap对象中的视图从默认的up = true north旋转到我选择的自定义角度,但无法在ggmap或get_map中找到选项。目前,我有以下代码:
map1< - get_map(location = c(-78.872209,35.050514),zoom = 17,maptype =hybrid)
ggmap(map1)
产生:
我想旋转图像,以便显示的主要街道(人街)垂直对齐,就像这样(我刚刚在screencapture软件中手动旋转):
我的目标当然是仍然有一个水平和垂直的x和y轴作为原始图像,但有实际的视口旋转。
在旋转的(和重新调整大小的)视口中绘制地图,但在相反的方向旋转标签。 lon标签的位置(hjust,vjust)需要稍微调整。如果旋转角度不太大,调整就可以了。
库(ggmap)
库(网格)
#获取地图$ b $ c $($)
lat <-c(-47.5,-33.5)
map1 < - get_map(location = c(-78.872209,35.050514),zoom = 17,maptype =hybrid)
#旋转角度
rotate = -67
#向相反方向旋转标签
#加上对刻度标记位置的调整
map = ggmap(map1)+
theme(axis.text.x = element_text(angle = -rotate,
vjust = 1.1,hjust =旋转> 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))
#在旋转的视口中绘制地图,调整大小
print(map ,vp = viewport(width = .7,height = .7,angle = rotate))
< a href =https://i.stack.imgur.com/nLe 7i.pngrel =nofollow noreferrer>
I am looking to rotate the view within the ggmap object from the default of up = true north, to a custom angle of my choosing, but can't find the option within ggmap or get_map. Currently, I have the following code:
map1 <- get_map(location=c(-78.872209, 35.050514), zoom = 17, maptype="hybrid")
ggmap(map1)
Which produces:
I would like to rotate the image so that the main street shown (Person Street) is vertically-aligned, like this (which I just rotated manually in a screencapture software):
My goal, of course, is to still have a horizontal and vertical x and y axis as the original image, but have the actual "viewport" be rotated.
Draw the map in a rotated (and re-sized) viewport, but rotate the labels in the opposite direction. The position (hjust, vjust) of the lon labels needs a little adjustment. If the angle of rotation isn't too big, the adjustment is okay.
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))
这篇关于你如何在ggmap中旋转地图的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!