plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

tooltip order not working

Open kent37 opened this issue 8 years ago • 13 comments

The tooltip argument to ggplotly does not seem to change the order of tooltips. For example with

ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
ggplotly(ggiris, tooltip = c("y", "x", "colour"))

I see a tooltip with order Species, Petal.Width, Sepal.Length, i.e. color, x, y.

Using ggplot 2.2.1 and plotly 4.5.6 with R 3.3.2 on Mac OS X.

kent37 avatar Jan 12 '17 17:01 kent37

Same here

stanstrup avatar Jan 24 '17 10:01 stanstrup

Is this issue solved yet? Thanks!

hjia222 avatar Jun 14 '18 20:06 hjia222

Same here

gustavo-utpott avatar May 28 '19 23:05 gustavo-utpott

I noticed several related odd behaviors with the tooltip argument in ggplotly().

For ggplot, the order and placement of aes's sometimes matters:

data(mtcars)
mtcars$text <- row.names(mtcars)
mtcars$x <- mtcars$disp
mtcars$y <- mtcars$mpg
mtcars$color <- mtcars$cyl

viz <- ggplot(mtcars, aes(x=x, y=y)) +
  geom_point(aes(text = text), alpha = 1/2)
ggplotly(viz, tooltip = c("y", "text", "x"))
ggplotly(viz, tooltip = c("y", "x", "text"))
ggplotly(viz, tooltip = c("text", "y", "x"))
## order = text, x, y  regardless of tooltip ordering

viz <- ggplot(mtcars, aes(x=x, y=y, color=color)) +
  geom_point(aes(text = text), alpha = 1/2)
ggplotly(viz, tooltip = c("color", "y", "text", "x"))
## order = text, x , y, color regardless of ordering

viz <- ggplot(mtcars, aes(x=x, y=y)) +
  geom_point(aes(text = text, color=color), alpha = 1/2)
ggplotly(viz, tooltip = c("color", "y", "text", "x"))
## order = text, color, x, y
## placing the aes within geom_point() instead of ggplot() changes where it shows up in the tooltip.

viz <- ggplot(mtcars) +
  geom_point(aes(text = text, color=color, x=x, y=y), alpha = 1/2)
ggplotly(viz, tooltip = c("color", "y", "text", "x"))
ggplotly(viz, tooltip = c("y", "text", "color", "x"))
## order = x, y, text, color
## x and y get priority and are placed first when placed within geom_point

viz <- ggplot(mtcars, aes(x=x, y=y)) +
  geom_point(aes(text = text, color=color, x=x, y=y), alpha = 1/2)
ggplotly(viz, tooltip = c("color", "y", "text", "x"))
## order = x, y, text, color, x, y 
## x and y labels are duplicated if placed in both ggplot() and geom_point()

viz <- ggplot(mtcars, aes(x=x, y=y)) +
  geom_point(aes(color=color, text = text), alpha = 1/2)
ggplotly(viz, tooltip = c("color", "y", "text", "x"))
## order = color, text, x, y
## color and text labels can be re-ordered based on the order they are defined within geom_point()

baderstine avatar Jun 19 '19 13:06 baderstine

same issue

mgei avatar Dec 03 '19 17:12 mgei

same issue ggplot2 3.2.1 + plotly 4.9.0

wendywangwwt avatar Apr 04 '20 22:04 wendywangwwt

Same issue on plotly_4.9.2.1 and ggplot2_3.3.0

jessecambon avatar May 11 '20 02:05 jessecambon

i found @baderstine 's approach to work well for moving the text label to the top relative to the other data in the tooltip.

nahuron avatar Oct 06 '20 15:10 nahuron

I think this issue should be classed as a "bug" rather than as an "enhancement" because the current behaviour does not agree with what the documentation of the tooltip argument to ggplotly() is saying. There it says:

The order of variables here will also control the order they appear. For example, use tooltip = c("y", "x", "colour") if you want y first, x second, and colour last.

gustavdelius avatar Jul 25 '21 17:07 gustavdelius

Hello, I found a way around it, please see below:

p <- ggplot(data = iris, aes(x = Petal.Width, y = Sepal.Length, color = Species, text = paste("y: ",y,"</br>colour: ",colour,"</br>x: ",x)) ) + geom_point()

ggplotly(p, tooltip = c("text"))

chanalim avatar Aug 11 '21 16:08 chanalim

@chanalim , that is very clever. Thank you very much for posting that workaround.

gustavdelius avatar Aug 11 '21 21:08 gustavdelius

As this issue is still open almost 6 years later, I wanted to kindly ask whether there is any chance that it will be closed anytime soon? Thanks for your work!

acmuehlhausen-smc avatar Dec 21 '22 14:12 acmuehlhausen-smc

For anyone looking - this is still an issue in 2024

Nova-Scotia avatar May 01 '24 15:05 Nova-Scotia