Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created September 24, 2014 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholstius/f723aa5cb8c54088f67c to your computer and use it in GitHub Desktop.
Save dholstius/f723aa5cb8c54088f67c to your computer and use it in GitHub Desktop.
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