【问题标题】:R Plotly - Change font and opacity of hoverinfoR Plotly - 更改 hoverinfo 的字体和不透明度
【发布时间】:2018-04-13 23:24:41
【问题描述】:

我正在尝试更改我的绘图图中的 hoverinfo 框的字体和不透明度(使用 R)。我使用了以下代码,但无法弄清楚如何更改悬停框的字体或不透明度,如果这可能的话?

plotC <- plot_ly(tg, x = ~FINPERCH, y = ~JourneyTime, type = 'scatter', mode = 'lines',color = ~PeakDirection, colors=pal, linetype = ~PeakDirection,height = 500, width = 1200,

hoverinfo= 'text', text = ~paste("<b>Period: </b>", FINPERCH,'<br><b>Direction / Peak :</b>', PeakDirection,'<br><b>Average Journey Time:</b>',JourneyTime,'mins'))%>%

我不想给图表本身添加任何注释。我只想设置悬停的字体和不透明度。

任何建议将不胜感激。 谢谢

【问题讨论】:

    标签: r fonts plotly opacity


    【解决方案1】:

    您可以使用htmltools::htmlDependency将CSS添加到绘图中,如this answer所示:

    library(htmltools)
    library(htmlwidgets)
    
    p <- plot_ly(mtcars, x=~cyl, y=~mpg) 
    
    
    x <- as_widget(p)                                 # convert to htmlwidget object 
    # add a the code directly into <head> using `htmltools::htmlDependency`
    x$dependencies <- c(x$dependencies,
      list(
        htmlDependency(
          name = "custom",
          version="1",
          src="",
          head='
            <style type="text/css">
            .hovertext {
                opacity: 0.5
            }
            </style>
          '
        )
      )
    )
    

    【讨论】:

    • 谢谢@aocall!
    • 不客气。如果这对您来说是正确的解决方案,您能接受答案吗?
    猜你喜欢
    • 2018-11-15
    • 2018-07-14
    • 2013-03-04
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-20
    • 1970-01-01
    相关资源
    最近更新 更多