Skip to content

issue: position_dodge alters hover values #986

Open
@rubenalv

Description

@rubenalv

Problem: using position_dodge in at least geom_point seems to incorrectly assign the group values shown when hovering on a point. This is related to whether or not the values in the plot x-axis factor are alphabetically ordered.

Example:

library(ggplot2)
library(plotly)

#Data with x-axis factor in alphabetical order (a, b, c):
data <- data.frame('Col1' = c('a', 'b', 'c'), 'Col2'= factor(1:3), Col3 = c('A1', 'A2', 'A3'), 'Val' = c(10,5,1))
#Hovering on plot dots gives correct values, regardless of position_dodge.
ggplotly(ggplot(data, aes(x = Col1, y = Val, group = Col2:Col3)) + geom_point())
ggplotly(ggplot(data, aes(x = Col1, y = Val, group = Col2:Col3)) + geom_point(position = position_dodge(0.6)))

#Data with x-axis factor in non alphabetical order (c, a, b):
data1 <- data.frame('Col1' = c('c', 'a', 'b'), 'Col2'= factor(1:3), Col3 = c('A1', 'A2', 'A3'), 'Val' = c(10,5,1))
#Hovering on plot dots gives correct values if no position_dodge is used:
ggplotly(ggplot(data1, aes(x = Col1, y = Val, group = Col2:Col3)) + geom_point())
#Hovering on plot dots gives incorrect values (as if the x-axis levels had been reordered?) if position_dodge is used:
ggplotly(ggplot(data1, aes(x = Col1, y = Val, group = Col2:Col3)) + geom_point(position = position_dodge(0.6)))

Both solution and temporary workaround are appreciated. Plotly is superb, thank you so much for putting your time on it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions