Search code examples
rgoogle-visualizationdata-visualizationlinechartgooglevis

R: Cannot remove x and y-axis gridlines on googleVis LineChart


As the title says it, I'm wondering why I cannot remove gridlines from the chart area on gvisLineChart objects in R. I've had a read through the documentation and tried using the respective commands written there - namely:

options = list( 
             hAxis.gridlines = "{color:'transparent', count:0}",
             vAxis.gridlines = "{color:'transparent', count:0}"
          )

I also tried implementing the suggested solutions in this stackoverflow thread, but none of it has worked. Below is a snippet of the code I am using to construct the line chart, as well as an overview of my data & a screenshot of the resulting plot.

Here is my data:

> str(df)
'data.frame':   5715 obs. of  2 variables:
$ Date: Date, format: "2022-07-21" "2022-07-20" "2022-07-19" "2022-07-18" ...
$ Open: num  14.4 14 14.2 15.3 13.7 ...

Here is the code I am using to build the plot:

p <- gvisLineChart(
            df,
            options=list(
                title="SIGA Historic Price Chart",
                legend="bottom",
                lineWidth = 1,
                height = 450,
                width = 900,
                hAxis.gridlines = "{color:'transparent', count:3}",
                vAxis.gridlines = "{color:'transparent', count:3}",
                series = "[{color: '#00D1B2'}]",
                chartArea = "{width:\"85%\",height:\"70%\"}",
                tooltip = "{textStyle: {color: 'black'}, showColorCode: true}"
            )
        )
plot(p)

Here is a screenshot of the resulting plot:

enter image description here

I want to remove these gridlines, the axis ticks and the bold horizontal line that goes through y=0 to give the plot a very minimalistic look. How can I do this with R, granted that I've exhausted the above mentioned suggestions to no avail? Thanks.


Solution

  • try the following format, to ensure hAxis exists as an object...

    hAxis = "{gridlines: {color:'transparent', count:0}}",  
    

    EDIT

    to remove the lines but keep the labels, remove count: 0
    to change the color of the baseline (bold horizontal line going through y = 0),
    use option baselineColor

    hAxis = "{baselineColor: 'transparent', gridlines: {color:'transparent'}}",