Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd83af1

Browse files
committed
Fix tooltip with wrong group information
Closes #774
1 parent 51876e1 commit bd83af1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

‎R/ggplotly.R‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,19 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
174174

175175
# Compute aesthetics to produce data with generalised variable names
176176
data <- by_layer(function(l, d) l$compute_aesthetics(d, plot))
177-
177+
178+
# The computed aesthetic codes the groups as integers
179+
# Here we build a map each of the integer values to the group label
180+
group_maps <- Map(function(x, y) {
181+
tryCatch({
182+
x_group <- x[["group"]]
183+
names(x_group) <- y
184+
x_group <- x_group[!duplicated(x_group)]
185+
x_group
186+
}, error = function(e) NULL
187+
)
188+
}, data, groupDomains)
189+
178190
# Transform all scales
179191
data <- lapply(data, ggfun("scales_transform_df"), scales = scales)
180192

@@ -205,7 +217,17 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
205217

206218
# Reparameterise geoms from (e.g.) y and width to ymin and ymax
207219
data <- by_layer(function(l, d) l$compute_geom_1(d))
208-
220+
221+
# compute_geom_1 can reorder the rows from `data`, making groupDomains
222+
# invalid. We rebuild groupDomains based on the current `data` and the
223+
# group map we built before.
224+
groupDomains <- Map(function(x, y) {
225+
tryCatch({
226+
names(y)[match(x$group, y)]
227+
}, error = function(e) NULL
228+
)
229+
}, data, group_maps)
230+
209231
# Apply position adjustments
210232
data <- by_layer(function(l, d) l$compute_position(d, layout))
211233

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /