issue: position_dodge alters hover values
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two ggplotly examples using geom_point and position_dodge, comparing the alphabetical and non-alphabetical Col1 cases. Trace how ggplotly transfers grouped point data into hover values; done means the displayed group values remain matched to the correct points when position_dodge is used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100