Home > front end >  Getting the name of the point while hovering it in R
Getting the name of the point while hovering it in R

Time:12-31

Important note below

If you want to try it, here's the dataframe: enter image description here

I would like to be able to hover over the points for them to give me their name on the dataframe so I tried countless different ways to call this function (changing the parameters I mean):

ggplotly(p, tooltip = "name")

However, hovering the plot in this case only gives info about the cluster (1, 2, 3 or 4) and not the names of the points.

Additionally, I tried something that actually kinda works, but you'll see why not. If instead I did the original plot without specifying the geom = "point", so like this:

p <- fviz_cluster(k4, data=df_cluster,palette = "Set2", ggtheme = theme_minimal())
ggplotly(p, tooltip = "name")

Hovering actually works properly but the names of each point are also shown at all times resulting in something horrible:

enter image description here

Again, here, overing a specific point does actually show a pop-up with it's name but I would like that without having all the others constantly shown.

Any ideas? Thank you in advance!

Note:

There's this same question (answered) here: enter image description here

This shiny app will open. There is a button for you to upload your data file. Pick your .csv file. The plot you show above should automatically appear. You can click on any of the points and the information for that point will be displayed in the box below.

Shiny app

  • Related