I am trying to change the font and opacity of the hoverinfo box within my plotly graph (using 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 :
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>
'
)
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.