2017-04-19 25 views
0

我需要在地圖上製作一個網絡,並帶有適當的地理參考。在地圖上使用R中的geomnet

我試圖讓這樣的事情: https://cran.r-project.org/web/packages/ggCompNet/vignettes/examples-from-paper.html

(看下方地圖) 這是tripnet的頭:

from_id to_id q_trx  long  lat 
9 20020101  0 241 -58.41441 -34.60768 
10 20020102 20040108 537 -58.41950 -34.60722 
11 20020102  0 561 -58.41950 -34.60722 
12 20020103 20040108 543 -58.42359 -34.60714 
13 20020103  0 551 -58.42359 -34.60714 
14 20020104 20040108 490 -58.42688 -34.60397 

這裏是我的代碼:

map <- get_map(location = c("long" = -58.416212, "lat" = -34.631330), zoom = 12) 


ggmap(map) + geom_net(
    data = tripnet, 
    labelon = TRUE, 
    selfloops = TRUE, 
    vjust = -0.5, 
    ealpha = 0.5, 
    aes(
    from_id = from_id, 
    to_id = to_id, 
    x = long , 
    y = lat, 
    linewidth = q_trx, 
    colour = 'grey' 
) 
) + 
    scale_colour_manual("CABA", values = c("grey40")) + theme_net() %+replace% theme(aspect.ratio = 
                           NULL, legend.position = "bottom") + coord_map() 

顯然沒有錯誤,但它只是繪製一張沒有網絡的地圖。

回答

1

我剛纔注意到每個節點都需要有它的座標。以前,我已經在q_trx中刪除了具有NA值的所有行。包括他們解決了這個問題。