I created a dataframe containing coordinates of a start- and endpoint on each row, adding an sfc column made from those coordinates, resulting in something of the same structure as this minimal example:
df <- structure(list(week_index = 1L, start_lat = 41.83070705, start_lng = -87.64125533, end_lat = 41.85792183, end_lng = -87.66854383, geometry = structure(list( structure(c(41.83070705, 41.85792183, -87.64125533, -87.66854383 ), .Dim = c(2L, 2L), class = c("XY", "LINESTRING", "sfg" ))), class = c("sfc_LINESTRING", "sfc"), precision = 0, bbox = structure(c(xmin = 41.83070705, ymin = -87.66854383, xmax = 41.85792183, ymax = -87.64125533 ), class = "bbox"), crs = structure(list(input = NA_character_, wkt = NA_character_), class = "crs"), n_empty = 0L)), row.names = c(NA, -1L), sf_column = "geometry", agr = structure(c(week_index = NA_integer_, start_lat = NA_integer_, start_lng = NA_integer_, end_lat = NA_integer_, end_lng = NA_integer_), class = "factor", .Label = c("constant", "aggregate", "identity")), class = c("sf", "tbl_df", "tbl", "data.frame" ))
str(df)
sf [1 × 6] (S3: sf/tbl_df/tbl/data.frame)
$ week_index: int 1
$ start_lat : num 41.8
$ start_lng : num -87.6
$ end_lat : num 41.9
$ end_lng : num -87.7
$ geometry :sfc_LINESTRING of length 1; first list element: 'XY' num [1:2, 1:2] 41.8 41.9 -87.6 -87.7
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
..- attr(*, "names")= chr [1:5] "week_index" "start_lat" "start_lng" "end_lat" ...
I try to plot this line as follows:
leaflet(df) |>
addProviderTiles(providers$CartoDB.Positron) |>
addPolylines() |>
setView( lat = mean(wallace35.post$start_lat),
lng = mean(wallace35.post$start_lng),
zoom = 19 )
However, the line does not appear. Any pointers as to why that is?