【问题标题】:How to put geocoordinates from a dataframe on a map in R?如何将数据框中的坐标放在R中的地图上?
【发布时间】:2020-10-29 14:44:19
【问题描述】:

我想为经度和纬度定义的多个位置绘制点和文本标签。它适用于单个位置,但我很难在 geom_point 中为一组数据扩展它。

library(ggplot2)
require(maps)

GER <- map_data("world", region = "Germany")

ggplot(GER, aes(x = long, y = lat, group = group)) +
  geom_polygon(fill="lightgray", colour = "white")+
  geom_point(aes(x = 13.404954, y = 52.520008), color="red")+
  geom_text(aes(x = 13.404954, y = 52.520008), label = "Berlin", color = "red", nudge_y = .2) 

df <- data.frame(name = c("Berlin", "Hamburg"), 
                 long = c(13.404954, 9.993682),
                 lat = c(52.520008, 53.551086))

# How to do it?
ggplot(GER, aes(x = long, y = lat, group = group)) +
  geom_polygon(fill="lightgray", colour = "white")+
  geom_point(aes(x = df$long, y = df$lat), color="red")

【问题讨论】:

    标签: r ggplot2 maps latitude-longitude


    【解决方案1】:

    必须明确两个不同的数据集

    ggplot(data = GER, aes(x = long, y = lat, group=group)) +
      geom_polygon(fill="lightgray", colour = "white")+
      geom_point(data = df, aes(x = long, y = lat, group=name), color="red")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多