2016-09-27 38 views
0

我有一个有4个坐标的数据框用于几个观测:经度从,纬度从,经度到纬度到。 我想做出地图上出现的细分,就像在plotly的机场示例中一样https://plot.ly/r/lines-on-maps/以坐标为基础的细分图从中心开始阴谋地图

我试图更改代码以适合我的数据框。该段确实通过坐标,但它不是从第一个坐标开始,而是在全球的中心,我不明白为什么。我不确定我做错了什么。

the plot as it appears

enter image description here

下面是代码:

geo <- list(
     scope = 'Europe', 
     projection = list(type = 'azimuthal equal area'), 
     showland = TRUE, 
     landcolor = toRGB("gray95"), 
     countrycolor = toRGB("gray80") 
    ) 

    plot_geo(locationmode = 'Europe', color = I("red")) %>% 
     add_markers(
     data = transfer.path.full[1:10,], x = ~lon_o, y = ~lat_o, text = ~name, hoverinfo = "text", alpha = 0.5 
    ) %>% 
     add_segments(
     data = group_by(transfer.path.full[1:10,],id), 
     x = ~lon_o, xend = ~lon_d, 
     y = ~lat_o, yend = ~lat_d, 
     alpha = 0.3, size = I(1), hoverinfo = "text" 
    ) %>% 
     layout(title = 'E T 2016', 
     geo = geo, showlegend = FALSE, height=800 
    ) 

赞赏任何帮助,谢谢!

+0

我在剧情论坛上发布了这个帖子,显然这是一个已知的问题,他们正致力于解决https://github.com/plotly/plotly.js/issues/963 –

回答

1

我刚才在其他问题上找到了答案。您将不得不使用split =~ some_id这与使用Tableau中的paths函数类似。

geo <- list(
    scope = 'Europe', 
    projection = list(type = 'azimuthal equal area'), 
    showland = TRUE, 
    landcolor = toRGB("gray95"), 
    countrycolor = toRGB("gray80") 
) 

plot_geo(locationmode = 'Europe', color = I("red")) %>% 
    add_markers(
    data = transfer.path.full[1:10,], x = ~lon_o, y = ~lat_o, text = ~name, hoverinfo = "text", alpha = 0.5 
) %>% 
    add_segments(
    data = group_by(transfer.path.full[1:10,],id), 
    x = ~lon_o, xend = ~lon_d, 
    y = ~lat_o, yend = ~lat_d, 
    alpha = 0.3, size = I(1), split =~ some_id, hoverinfo = "text" 
) %>% 
    layout(title = 'E T 2016', 
    geo = geo, showlegend = FALSE, height=800 
) 

此外,您可能需要添加color = I('blue')在同一线路上,使他们都相同的颜色。我还没有找到一种方法将它们全部分组在同一个传说组中,但是如果您遇到痕迹legendgroup,如果您遇到如何解决该问题,请告诉我!