mrjoh3 / c3

c3 HTMLWidget Ploting
39 stars 51 forks source link

c3_bar produces a barchart with no gaps between bars #2

Closed zhiboz closed 8 years ago

zhiboz commented 8 years ago

firstly, many thanks for a great package! trying to use c3_bar with the code below, which produces a bar chart with three bars in one group, with no gaps between bars. how may I code it to produce the bars in three separate groups. thanks!

library(c3)

data.frame(a=1, b=3, c=2) %>%
  c3() %>%
  c3_bar()
mrjoh3 commented 8 years ago

hi @zhiboz glad you like the package. C3 treats columns as a series of data so a single row will group bars as you describe. Adding an addition row illustrates the behavior

data.frame(a=c(1,2), b=c(3,2), c=c(2,1)) %>%
     c3() %>%
     c3_bar()

To separate the columns as you describe you need to restructure you data.frame and define the x axis within the c3() function.

data.frame(x=c('a','b','c'), y=c(1,3,2)) %>%
     c3(x='x') %>%
     c3_bar()
zhiboz commented 8 years ago

Thanks @mrjoh3! It works like a charm!