2017-04-07 31 views
0
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地圖繪製,但經度和緯度是完全關閉。我不完全確定發生了什麼事。例如,爲什麼是拉特。在地圖上超過100個?不正確的經度/緯度與ggplot

enter image description here

回答

0

您切換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") 
1

你混了經度和緯度。如果您將標籤添加到點上,您會看到沒有任何國家/地區被繪製在正確的位置。

所以要確保得到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") 
+1

英雄所見略同:) –

+0

天啊,昨天是三杯的咖啡還挺的一天。謝謝,甜菜根和Jeroen! – M85