3

I'm trying to change the color of the bars for a discreteBarChart using nPlot, but the color argument doesn't seem to change anything in the example below:

data(cars) 
speedTableVec<-table(cars$speed) 
speedTable<-data.frame(speedTableVec)
n1<-nPlot(Freq ~ Var1, data=speedTable, type="discreteBarChart", color="blue")
n1

Is there a way to keep the bars consistently one color (i.e. blue)? Thanks.

tonytonov
  • 25,060
  • 16
  • 82
  • 98

1 Answers1

3

Here is a solution. I presume you were looking to use NVD3 and nPlot. See here for the final chart.

data(cars) 
speedTableVec<-table(cars$speed) 
speedTable<-data.frame(speedTableVec)
require(rCharts)
n1 <- nPlot(Freq ~ Var1, data = speedTable, type="discreteBarChart")
n1$chart(color = "#! function(d){ return 'blue'} !#")

Hope this helps.

Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • You're presumption was correct that I'm looking to use nPlot. This is exactly what I was looking to do. Thanks! – Mario Nuñez Oct 08 '13 at 17:00
  • Follow-up. I'm trying to add an axis label, but `n1$chart(xAxis=list(axisLabel='Var1'))` doesn't seem to do the trick. Where am I going wrong? – Mario Nuñez Oct 08 '13 at 17:49
  • 3
    How do I pass on an array of colors, e.g. for plotting multiple lines in a lineChart with different colors? – pfifas May 21 '14 at 10:57