绘图地图中基于坐标的线段从中心开始

Coordinates-based segments in plotly map start from the center

我有一个带有 4 个坐标的数据框,用于几个观察:经度从、纬度从、经度到和纬度到。 我想制作出现在地图上的部分,如 plotly 的机场示例 https://plot.ly/r/lines-on-maps/

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

the plot as it appears

代码如下:

 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
      )

感谢任何帮助,谢谢!

我刚刚在我之前提出的另一个问题上找到了这个问题的答案。您将不得不使用 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 一样,如果您遇到如何解决这个问题,请告诉我!