更新 opts 已弃用;请改用theme。
如果您准备在ggplot2 中工作,ggmap 包可以轻松地向地图添加图层。下面的get_map() 函数获取巴布亚新几内亚莫尔兹比港国家研究所的卫星谷歌地图。 ggmap() 函数绘制地图,然后添加文本注释、线段注释和标题。但是可以像添加到常规 ggplot 图中一样添加其他几何图形。 gglocator() 函数的工作方式与基图中的locator() 类似。 lon 和lat 是地图中心的坐标,但位置向量可以给出地图的边界。我使用zoom 来获得正确的分辨率。
library(ggplot2)
library(ggmap)
library(grid)
nri = get_map(location = c(lon = 147.165, lat = -9.410), zoom = 18, maptype = 'satellite')
(NRImap = ggmap(nri, extent = "device") +
annotate('segment', x = 147.1656, xend = 147.1649, y = -9.41025, yend = -9.4096,
colour = 'white', arrow = arrow(length = unit(0.25,"cm")), size = 1) +
annotate('text', x = 147.1656, y = -9.41031, label = 'Conference Centre',
colour = 'white', size = 6) +
theme(plot.margin = unit(c(1.5, 0, 0, 0), "lines")) +
ggtitle ("National Research Institute") +
theme(plot.title = element_text(colour = "Blue", vjust = 2, size = 20)))
# gglocator()