0

I´ve gone thourgh some exemples but couldn´t fix the hover text

Here is a minimal exemple:

library(ggplot2)
library(plotly)

newhovertext=paste0(iris$Species,"<br>",iris$Sepal.Width)
g <- ggplot(iris,aes(x=Species,y=Sepal.Width,label=newhovertext)) + 
  geom_boxplot(alpha=0.5) 
 plotly::ggplotly(g,tooltip=label)

applying the above code will result in the following image:

image

I can´t display the plant names in the hover text, would appreciate some help

David
  • 8,113
  • 2
  • 17
  • 36
david
  • 805
  • 1
  • 9
  • 21

1 Answers1

1

you could do the following:

library(ggplot2)
library(plotly)
library(datasets)
data(iris)

newhovertext=paste0(iris$Species,"<br>",iris$Sepal.Width)
g<-ggplot(iris,aes(x=Species,y=Sepal.Width, label=newhovertext))+
  geom_boxplot(alpha=0.5)
g %>% ggplotly()

then it shows the labels while hovering, for more advanced solution you should consider using shiny.

you can see the resulted plot in: http://rpubs.com/david_sriker/555513

a different solution which you will see the other values:

gg_box <- iris %>%
  ggplot(aes(x=Species, y=Sepal.Width, text=paste("Species:",Species, "\n",
                                             "Width:", Sepal.Width))) +
  geom_boxplot()+

  #invisible layer of points
  geom_point(alpha = 0)

gg_box %>%
  ggplotly()

and you can see the resulted plot in: http://rpubs.com/david_sriker/555522

David
  • 8,113
  • 2
  • 17
  • 36