[英]R Plotly - Change font and opacity of hoverinfo
I am trying to change the font and opacity of the hoverinfo box within my plotly graph (using R). 我试图更改我的绘图图中hoverinfo框的字体和不透明度(使用R)。 I have used the following code but cannot work out how to change the font or the opacity of the hover box, if this is even possible?
我使用了以下代码,但是即使有可能,也无法解决如何更改字体或悬停框的不透明度。
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'))%>%
I do not want to add any annotations to the graph itself. 我不想向图形本身添加任何注释。 I only want to set the font and opacity of the hover.
我只想设置悬停的字体和不透明度。
Any advice would be greatly appreciated. 任何建议将不胜感激。 Thanks
谢谢
You can use htmltools::htmlDependency
to add CSS to the plot, as shown in this answer : 您可以使用
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.