0

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

M. Monti
  • 1
  • 1

1 Answers1

0

I'm achieving this simply by writting my dataframe value to the "weight" of the addPolylines function, so it goes like this :

addPolylines(data=ploy_df,
               lng = ~long, 
               lat = ~lat,
               weight = dest_df$val
Oscar Jnn
  • 154
  • 1
  • 19
  • Thanks for your answer Oscar. Unfortunately, it does not seem to work for me. I have altough found something closer to what I was looking for; it is the function **addFlows()** contained in the package **leaflet.minicharts**. https://cran.r-project.org/web/packages/leaflet.minicharts/vignettes/introduction.html – M. Monti Mar 26 '19 at 10:48