R 以不同颜色打印添加_段

R 以不同颜色打印添加_段,r,plotly,R,Plotly,我正在尝试创建一个机场网络,其中的节点为某些城市,具有连接两个不同城市的lat、long和EDGE。我可以得到网络,但我想用不同的颜色某些边缘。我在Indian_new_routes数据框中有一个颜色属性。但是,生成的新贴图以相同的颜色显示所有边。任何帮助都将不胜感激 `dput(head(vert.cord)) structure(list(name = c("2994", "2996", "2997", "2999", "3000", "3001"), Latitude = c(23.07

我正在尝试创建一个机场网络,其中的节点为某些城市,具有连接两个不同城市的lat、long和EDGE。我可以得到网络,但我想用不同的颜色某些边缘。我在Indian_new_routes数据框中有一个颜色属性。但是,生成的新贴图以相同的颜色显示所有边。任何帮助都将不胜感激

`dput(head(vert.cord))
structure(list(name = c("2994", "2996", "2997", "2999", "3000", 
"3001"), Latitude = c(23.077242, 19.862728, 19.088686, 23.287828, 
15.859286, 22.336164), Longitude = c(72.63465, 75.398114, 72.867919, 
69.670147, 74.618292, 73.226289), node.degree = c(18, 4, 86, 
2, 2, 4)), .Names = c("name", "Latitude", "Longitude", "node.degree"
), row.names = c(NA, 6L), class = "data.frame")`

`dput(head(Indian_new_routes))
structure(list(V1 = c("2994", "2994", "2994", "2994", "2994", 
"2994"), V2 = c("2997", "3007", "3017", "3043", "3093", "3098"
), weight = c(2653.62642910095, 861.186965956404, 1030.6558395446, 
3245.152405393, 4531.03569783294, 524.579803792743), dist = c(442.271071516825, 
861.186965956404, 515.327919772298, 1622.5762026965, 755.17261630549, 
524.579803792743), dist.inv = c(0.00226105676903165, 0.00116118803410992, 
0.00194051197622255, 0.000616303874257576, 0.001324200558135, 
0.00190628764731303), dist.inv.weight = c(0.000376842794838609, 
0.00116118803410992, 0.000970255988111277, 0.000308151937128788, 
0.0002207000930225, 0.00190628764731303), color = c("red", "red", 
"red", "red", "red", "red"), From.lat = c(23.077242, 23.077242, 
23.077242, 23.077242, 23.077242, 23.077242), From.lon = c(72.63465, 
72.63465, 72.63465, 72.63465, 72.63465, 72.63465), To.lat = c(19.088686, 
15.380833, 18.582111, 22.654739, 28.5665, 26.824192), To.lon = c(72.867919, 
73.831422, 73.919697, 88.446722, 77.103088, 75.812161)), .Names = c("V1", 
"V2", "weight", "dist", "dist.inv", "dist.inv.weight", "color", 
"From.lat", "From.lon", "To.lat", "To.lon"), row.names = c(NA, 
6L), class = "data.frame")`
geo%
添加\u段(
数据=印度新航线,
x=~From.lon,xend=~To.lon,
y=~From.lat,yend=~To.lat,
alpha=0.3,size=I(1),hoverinfo=“无”,color=~color
) %>%
布局(
标题='2015年1月印度国内航线
(悬停机场名称)', geo=geo,showlegend=FALSE,高度=800 )
根据给出的建议,一种可能的解决方案是:

geo <- list(
  scope = 'asia',
  projection = list(type = 'natural earth'),
  showland = TRUE,
  landcolor = toRGB("gray95"),
  countrycolor = toRGB("gray80")
  )
p <- plot_geo(locationmode = 'INDIA') %>%
  add_markers(
     data = vert.cord, x = ~Longitude, y = ~Latitude, text = ~name,
     size = ~node.degree, hoverinfo = "text", alpha = 0.5,  color = I("black")
  ) %>%

  add_segments(
    data = Indian_new_routes,
    x = ~From.lon, xend = ~To.lon,
    y = ~From.lat, yend = ~To.lat,
    alpha = 0.3, size = I(1), hoverinfo = "none", color = ~color
    ) %>%
  layout(
    title = 'Jan. 2015 Indian Domestic flight paths<br>(Hover for airport names)',
    geo = geo, showlegend = FALSE, height=800
    )
库(ggmap)
图书馆(dplyr)
图书馆(绘本)

根据给出的建议,一种可能的解决方案是:

geo <- list(
  scope = 'asia',
  projection = list(type = 'natural earth'),
  showland = TRUE,
  landcolor = toRGB("gray95"),
  countrycolor = toRGB("gray80")
  )
p <- plot_geo(locationmode = 'INDIA') %>%
  add_markers(
     data = vert.cord, x = ~Longitude, y = ~Latitude, text = ~name,
     size = ~node.degree, hoverinfo = "text", alpha = 0.5,  color = I("black")
  ) %>%

  add_segments(
    data = Indian_new_routes,
    x = ~From.lon, xend = ~To.lon,
    y = ~From.lat, yend = ~To.lat,
    alpha = 0.3, size = I(1), hoverinfo = "none", color = ~color
    ) %>%
  layout(
    title = 'Jan. 2015 Indian Domestic flight paths<br>(Hover for airport names)',
    geo = geo, showlegend = FALSE, height=800
    )
库(ggmap)
图书馆(dplyr)
图书馆(绘本)

我已经编辑了我的问题,并附上了vert.cord和Indian_new_routes数据集。请看一看。我已按上述格式添加了数据集。我已编辑了我的问题,并附上vert.cord和Indian_new_routes数据集。请看一看。我已经以上述格式添加了数据集。非常感谢您的回答。这真的很有帮助。非常感谢你的回答。这真的很有帮助。