library(leaflet)
library(leaflet.extras2)
library(sf)
data <- st_cast(st_as_sf(leaflet::atlStorms2005[4, ]), "LINESTRING")
data <- st_transform(data, 4326)
data <- data.frame(st_coordinates(data))
data$elev <- round(runif(nrow(data), 10, 500), 2)
data$L1 <- NULL
L1 <- round(seq.int(1, 4, length.out = nrow(data)))
data <- st_as_sf(st_sfc(lapply(split(data, L1), function(x) {
st_linestring(as.matrix(x))
})))
data$steepness <- 1:nrow(data)
data$suitability <- nrow(data):1
data$popup <- apply(data, 1, function(x) {
sprintf("Steepness: %sSuitability: %s", x$steepness, x$suitability)
})
leaflet() %>%
addTiles(group = "base") %>%
addHeightgraph(
color = "red", columns = c("steepness", "suitability"),
opacity = 1, data = data, group = "heightgraph",
options = heightgraphOptions(width = 400)
)
Run the code above in your browser using DataLab