I have the following R code
library(leaflet)
library(dplyr)
dest_df <- data.frame (lat = c(41.82, 46.88, 41.48, 39.14),
long = c(-88.32, -124.10, -88.33, -114.90),
val= c(3,4,5,6)
)
orig_df <- data.frame (lat = c(rep.int(40.75, nrow(dest_df))),
long = c(rep.int(-73.99,nrow(dest_df)))
)
dest_df$sequence <- c(sequence = seq(1, length.out = nrow(orig_df), by=2))
orig_df$sequence <- c(sequence = seq(2, length.out = nrow(orig_df), by=2))
orig_df=orig_df%>%
bind_cols(dest_df%>%
select(val))
ploy_df <- orig_df%>%
bind_rows(dest_df)%>%
arrange(sequence)
leaflet() %>%
addTiles() %>%
addPolylines(data=ploy_df,
lng = ~long,
lat = ~lat,
weight = ~val
)
What I'm trying to do is to mutate the weight of the line plotted on the map according to the value of a given variable (in this case, val). The output of the code is a map with lines of the same size.
What am I getting wrong?
Any help would be much appreciated. Best