if(interactive() && requireNamespace("tourr")) {
# 1D tour
p <- l_tour(iris[, -5], tour = tourr::grand_tour(1L))
# add layer density
l <- l_layer(l_getPlots(p),
stats::density(p['x']),
label = "density")
# as we scroll the bar, the density curve does not change
# unless the following function is executed
l_layer_callback.density <- function(target, layer, ...) {
layer <- loon::l_create_handle(c(l_getPlots(target), layer))
den <- stats::density(target['x'])
loon::l_configure(layer,
x = den$x,
y = den$y)
invisible()
}
}
Run the code above in your browser using DataLab