0

enter image description here

I grouped by player_name and used colour to differntiate between players. By using ggplotly player_name is shown twice. How can I avoid this?

ggplotly(ggplot(NBA_top, aes(season, y=player_height, colour=player_name, group=player_name)) + geom_point()+ geom_line())
y.eska
  • 67
  • 6
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Mar 28 '22 at 19:00

1 Answers1

2

The issue is that by default ggplotly will show the values of all aesthetics in the tooltip. As you mapped player_name on both the color and the group aes the player name will show up twice.

To prevent that you could set the aesthetics to be displayed in the tooltip via the tooltip argument. Note that for the color aes you have to use colour.

Using a simple example based on mtcars:

library(plotly)

ggplot(mtcars, aes(hp, mpg, color = factor(cyl), group = factor(cyl))) +
  geom_point()

Calling ggplotly without setting the tooltip argument gives a duplicated entry in the tooltip:

ggploty()

enter image description here

To prevent that you could set the tooltip argument:

ggplotly(tooltip = c("x", "y", "colour"))

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51