在地块上显示固定Map。此函数早于 geom_sf() 框架,并且不适用于 sf 几何列作为输入。但是,它可以与 geom_sf() 层和/或 coord_sf() 结合使用(请参阅示例)。
参数
- map
 - 
代表Map的 DataFrame 。有关详细信息,请参阅
geom_map()。 - ...
 - 
用于修改可视参数的其他参数,例如
colour或fill。 
例子
if (FALSE) {
if (requireNamespace("maps", quietly = TRUE)) {
# location of cities in North Carolina
df <- data.frame(
  name = c("Charlotte", "Raleigh", "Greensboro"),
  lat = c(35.227, 35.772, 36.073),
  long = c(-80.843, -78.639, -79.792)
)
p <- ggplot(df, aes(x = long, y = lat)) +
  annotation_map(
    map_data("state"),
    fill = "antiquewhite", colour = "darkgrey"
  ) +
  geom_point(color = "blue") +
  geom_text(
    aes(label = name),
    hjust = 1.105, vjust = 1.05, color = "blue"
  )
# use without coord_sf() is possible but not recommended
p + xlim(-84, -76) + ylim(34, 37.2)
if (requireNamespace("sf", quietly = TRUE)) {
# use with coord_sf() for appropriate projection
p +
  coord_sf(
    crs = sf::st_crs(3347),
    default_crs = sf::st_crs(4326),  # data is provided as long-lat
    xlim = c(-84, -76),
    ylim = c(34, 37.2)
  )
# you can mix annotation_map() and geom_sf()
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
p +
  geom_sf(
    data = nc, inherit.aes = FALSE,
    fill = NA, color = "black", linewidth = 0.1
  ) +
  coord_sf(crs = sf::st_crs(3347), default_crs = sf::st_crs(4326))
}}}
相关用法
- R ggplot2 annotation_logticks 注释:记录刻度线
 - R ggplot2 annotation_custom 注释:自定义grob
 - R ggplot2 annotation_raster 注释:高性能矩形平铺
 - R ggplot2 annotate 创建注释层
 - R ggplot2 aes_eval 控制审美评价
 - R ggplot2 aes 构建美学映射
 - R ggplot2 as_labeller 强制贴标机函数
 - R ggplot2 vars 引用分面变量
 - R ggplot2 position_stack 将重叠的对象堆叠在一起
 - R ggplot2 geom_qq 分位数-分位数图
 - R ggplot2 geom_spoke 由位置、方向和距离参数化的线段
 - R ggplot2 geom_quantile 分位数回归
 - R ggplot2 geom_text 文本
 - R ggplot2 get_alt_text 从绘图中提取替代文本
 - R ggplot2 geom_ribbon 函数区和面积图
 - R ggplot2 stat_ellipse 计算法行数据椭圆
 - R ggplot2 resolution 计算数值向量的“分辨率”
 - R ggplot2 geom_boxplot 盒须图(Tukey 风格)
 - R ggplot2 lims 设置规模限制
 - R ggplot2 geom_hex 二维箱计数的六边形热图
 - R ggplot2 scale_gradient 渐变色阶
 - R ggplot2 scale_shape 形状比例,又称字形
 - R ggplot2 geom_bar 条形图
 - R ggplot2 draw_key 图例的关键字形
 - R ggplot2 label_bquote 带有数学表达式的标签
 
注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Annotation: a map。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
