Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Concaveman in R using V8
# Using concaveman in R using V8
concaveman <- function(d){
library(V8)
ctx <- v8()
ctx$source('https://www.mapbox.com/bites/00222/concaveman-bundle.js')
jscode <- sprintf(
"var points = %s;var polygon = concaveman(points);",
jsonlite::toJSON(d, dataframe = 'values')
)
ctx$eval(jscode)
setNames(as.data.frame(ctx$get('polygon')), names(d))
}
# Example
d <- data.frame(
x = runif(100),
y = runif(100)
)
library(ggplot2)
ggplot(d, aes(x = x, y = y)) +
geom_point() +
geom_path(data = concaveman(d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment