简体   繁体   中英

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.

在此处输入图片说明

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> .

在此处输入图片说明

Any idea how to achieve this?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM