Question

I am trying to change the colours in a goolge stacked chart. I can not seem to replicate the suggestion given for color argument in the help file of 'gvisSteppedAreaChart'

df=data.frame(year=1:3, val1=c(1,3,4), val2=c(23,12,32))

SteppedArea1 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"),
                                     options=list(isStacked=TRUE))
plot(SteppedArea1)

SteppedArea1 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"),
                                     options=list(isStacked=TRUE),
                                     colors="{color:[red','#004411']}")
plot(SteppedArea2)

I think there is a typo in the help file, or perhaps I am not specifying a HTML color string correctly (my HTML is very hazy)?

Was it helpful?

Solution

I think the example in the docs for that function were missing a single quote. And your colors arg needs to be inside the options list. Note that the example is showing that you can use color names (e.g., red), and hex codes (e.g., #004411). This works for me:

library(googleVis)
df=data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
SteppedArea2 <- gvisSteppedAreaChart(df, xvar="country", yvar=c("val1", "val2"),
                                 options=list(isStacked=TRUE, colors="['red','#004411']"))
plot(SteppedArea2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top