-1

I am trying to generate bar plots / columns using rCharts(v 0.4.2). My problem is that I have an year's worth of data and I need to group on Months. So in Total I have 12 bars that I need to display. However, I have only 9 unique colors after which the colors start repeating. I read this documentation and tried inserting

colors <- c('#7cb5ec','#434348', '#90ed7d', '#f7a35c','#8085e9','#f15c80', '#e4d354','#2b908f','#f45b5b','#91e8e1')

into my code and then calling it as follows :

c <- hPlot(x = 'Confi', y = 'n', data = tablefinalC, type = 'bar', group = 'Month',title = "Inccode By confi", 
subtitle = "Bar Graph")

c$plotOptions(series = list(stacking = "normal",colors=paste0('colors'))
c$chart(backgroundColor = NULL)
c$set(dom = 'chart5')

However, I still get the same repetitive colors. So can someone please confirm how I can increase the amount of colors? Thanks in advance

Batanichek
  • 7,761
  • 31
  • 49
rantish
  • 79
  • 1
  • 8
  • May be problem here `colors=paste0('colors')` ... try `colors=colors` – Batanichek Feb 26 '16 at 09:32
  • Hi Batanicheck, I had used that option and also colors = 'colors' but it has no effect, I still got repeats - so I opted for the paste0 option just to check whether I was going wrong with the assignment of color. – rantish Feb 26 '16 at 10:45
  • Not `colors = 'colors'` .. if you write it colors== character string not variable which you difene early. try `colors1 <- c('#7cb5ec','#434348', '#90ed7d', '#f7a35c','#8085e9','#f15c80', '#e4d354','#2b908f','#f45b5b','#91e8e1')` then `colors=colors1` without `'` – Batanichek Feb 26 '16 at 11:38
  • Tried colors1 as suggested above but still the same issue – rantish Feb 26 '16 at 12:08

1 Answers1

0

You can create empty chart and then add series

Example

library(rCharts)
df=data.frame(x=1:10,y=-10:-1,z=letters[1:10],stringsAsFactors = F)
colors1=c( '#7cb5ec','#434348', '#90ed7d')
df$col=rep(colors1,round(nrow(df)/length(colors1),0)+1)[1:nrow(df)]

# Create new chart
a <- rCharts:::Highcharts$new()

# Set options
a$chart(type = "bar")
for(i in unique(df$z)){
  a$series(name=i,stacking = "normal" ,color=df$col[df$z==i], data= rCharts::toJSONArray2(df[df$z==i,], json=F, names=T)) 
}

a#plot

Result

enter image description here

Update( re-read question)

if you want to add more colors custominze colors1 and df$col

df=data.frame(x=1:20,y=-20:-1,z=letters[1:20],stringsAsFactors = F)
colors1=c( '#0048BA','#B0BF1A','#7CB9E8','#C9FFE5','#B284BE',
           '#5D8AA8','#00308F','#72A0C1','#AF002A','#F0F8FF',
           '#84DE02','#E32636','#C46210','#EFDECD','#E52B50',
           '#AB274F','#F19CBB','#AB274F','#D3212D','#3B7A57',
           '#FFBF00','#FF7E00','#FF033E','#9966CC','#A4C639',
           '#F2F3F4','#CD9575','#665D1E','#915C83','#841B2D'
)
df$col=colors1[1:nrow(df)]

Give you enter image description here

Batanichek
  • 7,761
  • 31
  • 49