rr-highcharter

Pattern fill in highcharter bar chart


I would like to create a column or bar chart with pattern fill in an R shiny app. It seems to me that highcharts and related highcharter package should be able to do the job, but I could not find a way. Here is what I tried based on this page: https://www.highcharts.com/docs/chart-design-and-style/pattern-fills

    library(highcharter)



hchart(iris,
       type = "column",
       hcaes(x=Species, y=Sepal.Length))%>%
  hc_plotOptions(
    series = list(
      borderColor = "blue",
      color= list(
        patternIndex = 0
      )
    )
  )

Solution

  • Fill patterns are implemented in a separate module which you have to add as a dependency using hc_add_dependency("modules/pattern-fill.js"):

    library(highcharter)
    #> Registered S3 method overwritten by 'quantmod':
    #>   method            from
    #>   as.zoo.data.frame zoo
    
    hchart(iris,
      type = "column",
      hcaes(x = Species, y = Sepal.Length)
    ) |> 
      hc_add_dependency("modules/pattern-fill.js") |> 
      hc_plotOptions(
        series = list(
          borderColor = "blue",
          color = list(
            patternIndex = 0
          )
        )
      )