Skip to content

Instantly share code, notes, and snippets.

@pbiecek
Created March 26, 2015 08:33
Show Gist options
  • Select an option

  • Save pbiecek/53cd69a682cae768e7c7 to your computer and use it in GitHub Desktop.

Select an option

Save pbiecek/53cd69a682cae768e7c7 to your computer and use it in GitHub Desktop.
labs <- function(data){
if(is.null(data)) return(NULL)
paste0("<b>",data$name, "</b><br/> ", data$x, " <br/>", data$y,"")
}
abline_data <- function (domain, intercept, slope) {
data.frame(x = domain, y = domain * slope + intercept)
}
layer_abline <- function (.vis, domain, intercept = 0, slope = 1, dash = 6, ...) {
df <- abline_data(domain, intercept, slope)
names(df) <- with(.vis$cur_props, c(x.update$value, y.update$value))
layer_paths(.vis, data = df, ..., strokeDash := dash)
}
df %>%
ggvis(x =~ x, y =~ y) %>%
group_by(name) %>%
layer_points(fill = ~gr, size.hover := 200,
fillOpacity := 0.9,
fillOpacity.hover := 0.95) %>%
layer_abline(c(7,10)) %>%
add_axis("x", title = group1) %>%
add_axis("y", title = group2) %>%
hide_legend(scales = "fill") %>%
add_tooltip(labs, "hover")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment