如何在传单下的R中绘制多行?

时间:2017-02-01 22:05:06

标签: r mapping leaflet linegraph

我在使用传单在R中绘制多行时遇到问题。我有纽约市车站的基本地图。我想从现有数据集中添加更多信息。数据集包含以下列:start_lng,start_lat,end_lng end_lat和total_trip。对于每一行,我想绘制一条分别连接起点和终点的线。然后两个站将连接,这代表一次旅行。我希望每排一趟。另外,对于着色,线段的暗度将基于total_trip。我怎么能这样做?感谢。

leaflet(sample) %>%
  addTiles() %>%
  setView(-73.9,40.7, zoom = 11) %>%
  addCircles(data = master_stations,lng = ~long, lat = ~lat, weight = 1, popup = ~name)

这是我数据集的一部分:

   start.station.id start.station.longitude start.station.latitude end.station.longitude end.station.latitude total_trip

              <dbl>                   <dbl>                  <dbl>                 <dbl>                <dbl>      <int>
1                72               -73.99393               40.76727             -74.00859             40.73620          2
2                72               -73.99393               40.76727             -73.99074             40.73455          2
3                72               -73.99393               40.76727             -73.97722             40.76341          2
4                72               -73.99393               40.76727             -73.98192             40.76527          2
5                79               -74.00667               40.71912             -73.98163             40.75206          2
6                79               -74.00667               40.71912             -73.98658             40.75514          2
7                79               -74.00667               40.71912             -73.98317             40.75527          2
8                79               -74.00667               40.71912             -73.98722             40.75300          2
9                83               -73.97632               40.68383             -73.97493             40.68981          4
10               83               -73.97632               40.68383             -73.98657             40.70149          2
# ... with 899 more rows

这是完整的数据集:

structure(list(start.station.id = c(72, 72, 72, 72, 79, 79), 
    end.station.id = c(238, 285, 352, 468, 153, 465), total_trip = c(2L, 
    2L, 2L, 2L, 2L, 2L), start.station.name = c("\"W 52 St & 11 Ave\"", 
    "\"W 52 St & 11 Ave\"", "\"W 52 St & 11 Ave\"", "\"W 52 St & 11 Ave\"", 
    "\"Franklin St & W Broadway\"", "\"Franklin St & W Broadway\""
    ), start.station.longitude = c(-73.99392888, -73.99392888, 
    -73.99392888, -73.99392888, -74.00666661, -74.00666661), 
    start.station.latitude = c(40.76727216, 40.76727216, 40.76727216, 
    40.76727216, 40.71911552, 40.71911552), end.station.name = c("\"Bank St & Washington St\"", 
    "\"Broadway & E 14 St\"", "\"W 56 St & 6 Ave\"", "\"Broadway & W 55 St\"", 
    "\"E 40 St & 5 Ave\"", "\"Broadway & W 41 St\""), end.station.longitude = c(-74.00859207, 
    -73.99074142, -73.97722479, -73.98192338, -73.9816324043, 
    -73.98658032), end.station.latitude = c(40.7361967, 40.73454567, 
    40.76340613, 40.7652654, 40.752062307, 40.75513557)), .Names = c("start.station.id", 
"end.station.id", "total_trip", "start.station.name", "start.station.longitude", 
"start.station.latitude", "end.station.name", "end.station.longitude", 
"end.station.latitude"), row.names = c(NA, -6L), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), vars = list(start.station.id), drop = TRUE, indices = list(
    0:3, 4:5), group_sizes = c(4L, 2L), biggest_group_size = 4L, labels = structure(list(
    start.station.id = c(72, 79)), row.names = c(NA, -2L), class = "data.frame", vars = list(
    start.station.id), drop = TRUE, .Names = "start.station.id"))

0 个答案:

没有答案