I am trying to play the ggplot2 plot using ggvis. The plot is aimed at representing the coordinates of points (from the analysis of correspondence) together with standard dispersion ellipses of clusters (hclust).
TL; DR
I would like to make a ggvis graph with multiple layers based on multiple datasets. Thus, the functional / pipe approach stops me from grouping one of the layers and not the other.
All (briefly commented) code is: https://gist.github.com/RCura/a135446cda079f4fbc10
Here is the code to create the data:
a <- rnorm(n = 100, mean = 50, sd = 5) b <- rnorm(n = 100, mean = 50, sd = 5) c <- rnorm(n = 100, mean = 50, sd = 5) mydf <- data.frame(A = a, B = b, C = c, row.names = c(1:100)) library(ade4) myCA <- dudi.coa(df = mydf,scannf = FALSE, nf = 2) myDist <- dist.dudi(myCA, amongrow = TRUE) myClust <- hclust(d = myDist, method = "ward.D2") myClusters <- cutree(tree = myClust, k = 3) myCAdata <- data.frame(Axis1 = myCA$li$Axis1, Axis2 = myCA$li$Axis2, Cluster = as.factor(myClusters)) library(ellipse)
I can build this via ggplot2:
library(ggplot2) myPlot <- ggplot(data=myCAdata, aes(x=Axis1, y=Axis2,colour=Cluster)) + geom_point(size=1.5, alpha=.6) + geom_vline(xintercept = 0, colour="black",alpha = 0.5, linetype = "longdash" ) + geom_hline(xintercept = 0, colour="black", alpha = 0.5, linetype = "longdash" ) + geom_path(data=df_ellipse, aes(x=x, y=y,colour=Cluster), size=0.5, linetype=1) myPlot

But I can not find how to build this with ggvis.
I can build 2 different layers:
library(ggvis) all_values <- function(x) { paste0(names(x), ": ", format(x), collapse = "<br />")} ggDF <- myCAdata ggDF$name <- row.names(ggDF)

Graph of ellipses (without tooltip tooltip)
myEllPlot <- ggvis(data = df_ellipse, x = ~x, y = ~ y) %>% group_by(Cluster) %>% layer_paths(x= ~x, y= ~y, stroke = ~Cluster, strokeWidth := 1) myEllPlot

But when I want to build 2 layers on the same plot:
myFullPlot <- ggvis(data = df_ellipse, x = ~x, y = ~ y) %>% layer_paths(x= ~x, y= ~y, stroke = ~Cluster, strokeWidth := 1) %>% layer_points(x = ~Axis1, y= ~Axis2, size := 15, fill= ~Cluster, data = ggDF) %>% add_tooltip(all_values, "hover") myFullPlot

Ellipses are not grouped, so the color does not fit, and the ellipses are not divided. If I try to group my ellipses, this will not work: group_by is only required for layer_paths, and this will ruin layer_points.
Any idea how to make this work? And sorry for this very long post, but I tried to make this work for hours: /