代码之家  ›  专栏  ›  技术社区  ›  Bastien

将水平线添加到R中plotly中的hoverinfo文本

  •  2
  • Bastien  · 技术社区  · 7 年前

    是否有方法将水平线添加到plotly hoverinfo框?我想要一些看起来有点像传单上的东西(线,而不是盒子的其余部分)。

    enter image description here

    我认为可以简单地添加html标记 <hr> 但它不起作用。

    下面是一个RE,它也显示了我的尝试:

    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")
    

    如下图所示,标签 <br> 被理解,但不是 <人力资源> .

    enter image description here

    你知道如何做到这一点吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Hallie Swan    7 年前

    从这个 help page ,仅支持某些HTML标记 plotly :

    Plotly使用HTML标记的子集来执行诸如换行符(<br>)之类的操作, 粗体(<b></b>),斜体(<i>),和超链接(<a href=–戥–戥–戥–gt;</a>)。标记(<);em>&书信电报;支持(>,和(<);sub>也支持。

    你可以 edit the plotly.js file 添加缺少的标记。看见 var TAG_STYLES source code .

    我考虑过 using LaTeX ,但不幸的是,LaTex排版 is currently broken .

    推荐文章