繁体   English   中英

R Plotly-更改hoverinfo的字体和不透明度

[英]R Plotly - Change font and opacity of 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添加到绘图中,如以下答案所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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