1

This is my first time posting a question on Stack Overflow. I will do my best to make this understandable.

I do not have enough rep to post an image...So I will describe what I have and what I want. I have an rCharts Highchart (must be this format) that is a barchart with 29 School Names as the categories and the value is Number of Children at each school. As there is only 1 series, all of the bars are the same color.

I need to change the color of specific bars based on a factor variable (type of school). I basically want to know if there is an equivalent to the fill=factor_variable in ggplot2. I do not want to make each different school type a series because I want to keep the school names along the axis.

Here is my code

agencyc <- rCharts:::Highcharts$new()
agencyc$chart(height=700, width=1000)
agencyc$title(text = "Number of Children at Agencies")
agencyc$subtitle(text = "2014/2015 Initiative Averages")
agencyc$xAxis(categories=stuagencycount$AgencyName)
agencyc$yAxis(title = list(text = "Number of Children"))
agencyc$data(x = stuagencycount$AgencyName, y = stuagencycount$Count, 
type = "bar", name = "Population", color="lightgreen")
agencyc$tooltip(headerFormat = "#! '' !#", valueDecimals=0, 
valueSuffix="Children")
agencyc$exporting(enabled = T)
agencyc$legend(enabled=F)
agencyc$print()
agencyc

Thanks for the help, may the force be with you

1 Answers1

0

From my understanding, you want to have bars with different colors even if they are in the same series.

The answer to this is setting a color property in the data object.

Please see working JSFiddle here.

I found this answer on stackoverflow. I had to add my JSFiddle as the one from the referenced answer was broken.

Community
  • 1
  • 1
Roco CTZ
  • 1,107
  • 1
  • 16
  • 31
  • Thanks Roco. That is pretty much what I am trying to do. My problem however is that I already know how to manipulate the JavaScript to get that, on this project I don't have access to the Javasript. I need to be able to do this within the R code. Also I would like to be able to make the color change a function rather than doing it by hand one by one. – Sean Palicki Jan 31 '15 at 19:10