rggplot2ggiraph

geom_dotplot_interactive() removes stacking of points


geom_dotplot_interactive() allows to create an interactive dotplot with the package ggiraph

library(dplyr)
library(ggplot2)
library(ggiraph)
p <- iris %>%
  ggplot(aes(x = Sepal.Length)) +
  geom_dotplot_interactive()
girafe(ggobj = p)

enter image description here

However, as soon as I try to add a tooltip, the points no longer stack.

p <- iris %>%
  mutate(rn = as.character(row_number())) %>% 
  ggplot(aes(x = Sepal.Length)) +
  geom_dotplot_interactive(aes(tooltip = rn))
girafe(ggobj = p)

enter image description here


Solution

  • Tooltip introduces a new grouping(?), which makes it necessary to change some of the default arguments of geom_dotplot_interactive to get the same result. Namely, determine binpositions across groups and stack across groups:

    p <- iris %>%
      mutate(rn = as.character(row_number())) %>% 
      ggplot(aes(x = Sepal.Length)) +
      geom_dotplot_interactive(aes(tooltip = rn), binpositions = "all", stackgroups = TRUE)
    girafe(ggobj = p)
    

    enter image description here