我正在尝试在我的情节图中更改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'))%>%
我不想在图表中添加任何注释。我只想设置悬停的字体和不透明度。
任何建议都将不胜感激。 感谢
答案 0 :(得分:0)
您可以使用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>
'
)
)
)