0

The following R code creates a line plot with markers. I wish to create a plot such that when hover is performed on the marker, it gives the "digits" and "sepw" values in the tooltip. Also the marker should be bold. Please help.

 digits = 1:150
 sep = iris$Sepal.Length
 sepw = iris$Sepal.Width
 plot_f1 <-  ggplot(iris, aes(x = digits)) + 
 geom_line(aes(y = sep, color = "red", label = sepw )) + geom_point(y = sep)
 plot_f1 = ggplotly(plot_f1)
 plot_f1
AK94
  • 325
  • 1
  • 5
  • 11
  • 2
    YOu can check [here](https://stackoverflow.com/questions/38917101/how-do-i-show-the-y-value-on-tooltip-while-hover-in-ggplot2) – akrun Aug 09 '17 at 06:40
  • just `ggplotly(plot_f1, tooltip = c("x","label"))` will work – parth Aug 09 '17 at 06:47

1 Answers1

1

Here is a first solution for your problem:

library(ggplot2)
library(plotly)

digits = 1:150
sep = iris$Sepal.Length
sepw = iris$Sepal.Width
plot_f1 <-  ggplot(iris, aes(x=digits, y=sep, label=sepw)) + 
            geom_line(color="red") + geom_point()
plot_f1 <- ggplotly(plot_f1, tooltip=c("x","label"))
plot_f1

enter image description here

A second solution is based on the text aesthetic:

plot_f2 <-  ggplot(data=iris, aes(x=digits, y=sep, group=1, 
                   text=paste("Sepw =",sepw,"<br />Digits =",digits))) + 
            geom_line(color="red") + geom_point()
plot_f2 <- ggplotly(plot_f2, tooltip="text")
plot_f2

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58