Search code examples
rgooglevis

Change the chartArea background color of gvisAnnotationChart


How to change the chartArea background color of gvisAnnotationChart?

I tried this but didn't work (I tried to replicate what I saw in this answer)

gvisAnnotationChart(
...,
options = list(
    ...,
    chart = list(
      backgroundColor = "#D3D3D3"
    )
  )
)

Solution

  • This is using one of the charts in the package demo, with an option for background color designated so you can see how it's documented.

    Because the gvisAnnotationChart has side panels, chart area, chart, and other designated panel-type areas, all of which could have different backgrounds, you have to be really specific for this type of chart.

    library(googleVis)
    data(Stock)
    
    plot(gvisAnnotationChart(Stock, datevar="Date",
                             numvar="Value", idvar="Device",
                             titlevar="Title", annotationvar="Annotation",
                             options=list(
                               displayAnnotations=TRUE,
                                   # make it blue
                               chart = "{chartArea:{backgroundColor:'#003b70'}}",
                               legendPosition='newRow',
                               width=600, height=350)))
    

    enter image description here