R Ploly-更改hoverinfo的字体和不透明度 [英] R Plotly - Change font and opacity of hoverinfo

查看:0
本文介绍了R Ploly-更改hoverinfo的字体和不透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改我的绘图图形中的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'))%>%

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

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

推荐答案

可以使用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>
      '
    )
  )
)

这篇关于R Ploly-更改hoverinfo的字体和不透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆