plotly.R
plotly.R copied to clipboard
tooltip order not working
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.
Same here
Is this issue solved yet? Thanks!
Same here
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()
same issue
same issue ggplot2 3.2.1 + plotly 4.9.0
Same issue on plotly_4.9.2.1 and ggplot2_3.3.0
i found @baderstine 's approach to work well for moving the text label to the top relative to the other data in the tooltip.
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.
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 , that is very clever. Thank you very much for posting that workaround.
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!
For anyone looking - this is still an issue in 2024