传单中的飞行路径

时间:2019-09-18 20:51:45

标签: r leaflet maps

我想在传单中将总部位置绘制为将总部位置与其分支连接起来的圆和线。数据的结构与图上的飞行路线示例完全相同(请参见示例:

https://plot.ly/r/lines-on-maps/)。

我需要一张交互式地图,显示堪萨斯州,内布拉斯加州的部分地区,科罗拉多州的部分地区和密苏里州的部分地区(河流,街道,城镇等)的地理位置。我希望弹出窗口显示这些位置。因此,我认为Leaflet可能比完成该任务要好。

我目前打算这样做的是: enter image description here

这是我的地图的代码:

library(plotly)
library(dplyr)


# HQ locations
HQ <- read.csv('HQ.csv', stringsAsFactors=FALSE, fileEncoding="UTF-8-BOM")
j <- c(17:18)
HQ[ , j] <- apply(HQ[ , j], 2,            # Specify own function within apply
                       function(x) as.numeric(as.character(x)))

# Storage Locations from HQ
Storage <- read.csv('Storage.csv', stringsAsFactors=FALSE, fileEncoding="UTF-8-BOM")

#COLUMN NUMBER

Storage$id <- seq_len(nrow(Storage))
i <- c(16:18)
Storage[ , i] <- apply(Storage[ , i], 2,            # Specify own function within apply
                       function(x) as.numeric(as.character(x)))

colnames(HQ)

# map projection
geo <- list(
  scope = 'usa',
  projection = list(
    type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB("lightgray"),
  showlaKes = T,
  lakecolor = toRGB('white'),
  lonaxis = list(range = c(-108, -95)),
  lataxis = list(range = c(37, 42)))


p <- plot_geo(locationmode = 'USA-states', color = I("purple")) %>%
  add_markers(
    data = HQ, x = ~Lng_HQ, y = ~Lat_HQ, text = ~paste('</br><b> Co-op Name:</b> ',

                                                       Cooperative,
                                                        '</br><b> Co-op HQ Location:</b> ', Headquarter,
                                                        '</br><b> Grain Capacity (bu):</b> ', Grain.Capacity..in.bushels.,
                                                        '</br><b> Grain Storage Locations:</b> ', CNGL
                                                        ),
    size = ~CNGL, hoverinfo = "text", alpha = 0.5
  ) %>%
  add_segments(
    data = group_by(Storage, id),
    x = ~Lng_HQ, xend = ~Lng,
    y = ~Lat_HQ, yend = ~Lat,
    alpha = 0.3, size = I(1), hoverinfo = "text", text =~paste('</br><b> Co-op Name:</b> ',

                                                               Cooperative,
                                                               '</br><b> Co-op Branch Location:</b>', Storage$Branch,
                                                               '</br><b> Grain Capacity (bu):</b> ', Storage$Grain.Capacity..in.bushels.)) %>%
  layout(
    title = ' <b>Map of All Cooperatives with Grain Locations</b><br>(Hover for Cooperative & Grain Storage Details)',
    geo = geo, showlegend = F, autosize = F, height=1000, width=1000, margin = m 
  )

p

0 个答案:

没有答案