Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
layer_abline() for ggvis
abline_data <- function (domain, intercept, slope) {
data.frame(x = domain, y = domain * slope + intercept)
}
untick <- function (x) {
stopifnot(all(sapply(x, is.name)))
str_replace_all(as.character(x), "`", "")
}
layer_abline <- function (.vis, domain, intercept = 0, slope = 1, dash = 6, ...) {
df <- abline_data(domain, intercept, slope)
names(df) <- with(.vis$cur_props, untick(c(x.update$value, y.update$value)))
layer_paths(.vis, data = df, ..., strokeDash := dash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment