0

I create a basic plotly scatter plot with a line of average added. Is it possible to add hoverinfo text like: "Average : <Average Value>" ? Another solution would be the text to be permanently displayed over the line but I think that this might be more complex.

pts<-c(10,20,30)
npts<-c(24,56,78)
ex<-data.frame(pts,npts)


library(plotly)
p <- plot_ly(data = ex, x = ~pts, y = ~npts,
             marker = list(size = 10,
                           color = 'white',
                           line = list(color = 'rgba(152, 0, 0, .8)',
                                       width = 2))) %>%
  add_segments(x = 0, xend = max(ex$pts), y = mean(ex$npts), yend =mean(ex$pts) )%>%
  add_trace(
    text = ~paste("Team Pts: ", pts, '</br>Fantasy Pts:', npts),
    hoverInfo='text'
  )
p
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • this might be helpful: https://stackoverflow.com/questions/38955568/line-segments-or-rectangles-with-hover-information-in-r-plotly-figure – Ben Aug 16 '19 at 19:53
  • tnx I would prefer a plotly solution – firmo23 Aug 16 '19 at 20:22
  • 1
    One of the answers is a plotly solution with multiple points on line without markers – Ben Aug 16 '19 at 20:23
  • indeed very useful – firmo23 Aug 16 '19 at 20:41
  • 1
    Possible duplicate of [Line segments or rectangles with hover information in R plotly figure](https://stackoverflow.com/questions/38955568/line-segments-or-rectangles-with-hover-information-in-r-plotly-figure) – M-- Aug 19 '19 at 01:11

0 Answers0