Search code examples
rgoogle-visualizationshinygooglevis

Coloring different levels in gvis Column Chart


I am trying to use gvis Column chart in R shiny. I have just 1 column with multiple levels and I want to color different levels with different colors. I,m not able to achieve this.

Eg. Data

     Gender Count
   1 Female   309
   2   Male   280

My Code :

        colGvis <- gvisColumnChart(reqData)

Output :

enter image description here

I want different colors for male and female.

If there are other gvis charts that can do the same, let me know.


Solution

  • googleVis requires you add column roles to your data.frame for aesthetics mapping.

    # Add role column
    reqData$Count.style = c('blue','green') 
    
    colGvis<-gvisColumnChart(reqData,
                             xvar = "Gender",
                             yvar = c("Count","Count.style")) # Include in yvar
    
    plot(colGvis)
    

    enter image description here