Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to include hover in a plotly layout element

$
0
0

I am stuck with the following plotly example which I would like to exploit:

library(plotly)
p <- plot_ly(economics, x = ~date, y = ~uempmed, name = "unemployment")

# add shapes to the layout
p <- layout(p, title = 'Highlighting with Rectangles',
             shapes = list(
               list(type = "rect",
                    fillcolor = "blue", line = list(color = "blue"), opacity = 0.3,
                    x0 = "1980-01-01", x1 = "1985-01-01", xref = "x",
                    y0 = 4, y1 = 12.5, yref = "y"),
               list(type = "rect",
                 fillcolor = "blue", line = list(color = "blue"), opacity = 0.2,
                 x0 = "2000-01-01", x1 = "2005-01-01", xref = "x",
                 y0 = 4, y1 = 12.5, yref = "y")))

How can I include hover information for those rectangles? Neither of the following works:

layout(p, title = 'Highlighting with Rectangles',
            shapes = list(
              list(type = "rect",
                   fillcolor = "blue", line = list(color = "blue"), opacity = 0.3,
                   x0 = "1980-01-01", x1 = "1985-01-01", xref = "x", 

                   # text - hoverinfo pair
                   text = "hello", hoverinfo = "text",
                   y0 = 4, y1 = 12.5, yref = "y"),
              list(type = "rect",
                   fillcolor = "blue", line = list(color = "blue"), opacity = 0.2,
                   x0 = "2000-01-01", x1 = "2005-01-01", xref = "x", 

                   # hovertext
                   hovertext = "good bye",
                   y0 = 4, y1 = 12.5, yref = "y")))

Is there any way how I can plot rectangles in plotly and apply a hover to them. Unfortunately, at least as I am aware of, there is no type = "rect" or anything like that available in R.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>