【问题标题】:Incorrect Long/Lat Plotting with ggplot使用 ggplot 绘制不正确的 Long/Lat
【发布时间】:2017-04-07 15:35:33
【问题描述】:
dat <- read.table(text=" 'Country_of_Asylum' 'ISO_3' 'Refugees_1000_inhabitants' Lat Long
    Lebanon LBN   208.91 33.8333  35.8333
    Jordan  JOR    89.55 31.0000  36.0000
    Nauru   NRU   50.60 -0.5333 166.9167
    Chad   TCD    30.97 15.0000  19.0000
    Turkey   TUR  23.72 39.0000  35.0000
    'South Sudan'   SSD 22.32  4.8500  31.6000
    Mauritania   MRT  19.36 20.0000 -12.0000
    Djibouti   DJI    16.88 11.5000  43.0000 Sweden   SWE  14.66 62.0000  15.0000 Malta   MLT  14.58 35.9000  14.4000", header=TRUE)

data.frame(top_ten_pcapita)
library(ggplot2)
library(maps)
mdat <- map_data('world')
str(mdat)
ggplot() + 
  geom_polygon(dat=mdat, aes(long, lat, group=group), fill="grey50") +
  geom_point(data=top_ten_pcapita, 
             aes(x=Lat, y=Long, map_id=ISO_3, size=`Refugees_1000_inhabitants`), col="red")       

我试图在 ggplot 上制作地图,但经度和纬度完全关闭。我不完全确定发生了什么。例如,为什么是 lat。在地图上超过 100 个?

【问题讨论】:

    标签: ggplot2 maps


    【解决方案1】:

    您混淆了经度和纬度。如果您为您的点添加标签,您会发现没有一个国家被绘制在正确的位置。

    所以请确保 x = Longitude 和 y = Latitude 并且它会起作用:

    ggplot() + 
      geom_polygon(dat = mdat, aes(long, lat, group = group), fill = "grey50") +
      geom_point(data = top_ten_pcapita, 
                 aes(x = long, y = lat, size = Refugees_1000_inhabitants), col = "red")
    

    【讨论】:

    • 天哪,昨天是喝三杯咖啡的日子。谢谢,甜菜根和 Jeroen!
    【解决方案2】:

    您切换了 x 轴和 y 轴。 x 应该是经度,y 应该是纬度。另外,我认为瑙鲁不应有负经度。

    试试这个:

    ggplot() + 
      geom_polygon(dat=mdat, aes(long, lat, group=group), fill="grey50") +
      geom_point(data=top_ten_pcapita, 
                 aes(x=Long, y=Lat, size=`Refugees_1000_inhabitants`), col="red") 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 2019-06-29
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      相关资源
      最近更新 更多