在地塊上顯示固定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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
