Search code examples
rhighchartsr-highcharter

How to adjust transparency of inactive series in highcharter with R


I am using the R package {highcharter} to make a plot similar to this highchart steamgraph.

So far, no major issues. However, I cannot replicate the nice fade animation which occurs with hovering the tooltip.

Bottom line: When I hove over a series, I want the other (inactive) series to fade.

Here is an example of my highcharter plot.

highchart() %>%
  hc_chart(type = "area", zoomType = "x") %>%
  hc_title(text = "Steamgraph of groups") %>%
  hc_xAxis(categories = c("1", "2", "3", "4", "5", "6", "7", "8", 
"9", "10"), 
       tickmarkPlacement = "on", 
       title = list(enabled = FALSE), 
       crosshair = TRUE, 
       labels = list(align = "left", reserveSpace = FALSE, rotation = "270"), 
       lineWidth = 0, 
       margin = 20, 
       tickWidth = 0) %>%
  hc_yAxis(title = list(text = "count"), 
       visible = FALSE) %>%
  hc_legend(enabled = FALSE) %>%
  hc_plotOptions(series = list(
states = list(
  inactive = list(
    opacity = 0.5
  )
)
)
) %>%
hc_add_series(name = "Group 1", 
            type = "streamgraph", 
            data = c(10, 49, 30, 22, 14, 6, 4, 7, 49, 48))  %>%
hc_add_series(name = "Group 2", 
            type = "streamgraph", 
            data = c(54, 12, 82, 42, 12, 6 ,23, 35, 15, 66))

I have tried to adjust the plotOptions but with no success.

Is there a different place to add this parameter?

Thanks


Solution

  • Your code is working fine. The inactive state was added to Highcharts in 7.1.0. The newest Highcharter uses 7.2.0 (11th February 2020), but you are probably using the older version which doesn't provide inactive state.