Bastien
Bastien

Reputation: 3097

Add horizontal line to hoverinfo text in plotly in R

Is there a way to add an horizontal line to plotly hoverinfo box? I want something that looks a little bit like that (the line, not the rest of the box) which was obtain with leaflet.

enter image description here

I thought it was possible to simply add the html tag <hr> but it isn't working.

Here is a RE which also shows what I tried:

library(plotly)
set.seed(123)
dd <- data.frame(
  xx = rnorm(10),
  yy = rnorm(10),
  ff = as.factor(c("a","b","c","a","b","c","a","a","b","c")),
  ss = round(runif(10, 100,1000))
)

pp <- plot_ly(data = dd,
              x = ~xx,
              y = ~yy,
              hoverinfo = 'text',
              text = ~paste(ff,
                            '</br></hr>',
                            "</br>value:", ss,
                            '</br><hr>',
                            '</br><hr><hr/>',sep=""))
add_markers(pp,mode = "markers")

As you can see in the figure below, the tag <br> is understood but not the <hr>.

enter image description here

Any idea how to achieve this?

Upvotes: 2

Views: 894

Answers (1)

Hallie Swan
Hallie Swan

Reputation: 2764

From this help page, only some HTML tags are supported by plotly:

Plotly uses a subset of HTML tags to do things like newline (<br>), bold (<b></b>), italics (<i>), and hyperlinks (<a href=’…’></a>). Tags <em>, <sup>, and <sub> are also supported.

You could edit the plotly.js file to add the missing tags. See var TAG_STYLES in the source code.

I considered using LaTeX, but unfortunately, LaTex typesetting is currently broken.

Upvotes: 1

Related Questions