3

Here is my data:

    rawData <- structure(list(Date = c("4/30/2015", "5/1/2015", "5/2/2015", 
"5/3/2015", "5/4/2015", "5/5/2015"), Amount = c(23L, 43L, 32L, 
43L, 43L, 32L)), .Names = c("Date", "Amount"), class = "data.frame", row.names = c(NA, 
-6L))

The following comes out blank:

rPlot(Amount~Date, data = rawData, type = 'bar')

I have no idea why -- I'm new to rCharts though -- I usually use ggplot2.

Thanks for your help

user1357015
  • 11,168
  • 22
  • 66
  • 111

1 Answers1

2

I 've seen as many tutorials or blogs as I could find about rCharts and there is no example of rPlot being used with a bar type anywhere with a data set similar to yours (there is only one here but it is being used as a histogram with binned variables and counts which is not the same).

The rPlot function works fine if you change the bar type to line, which makes me think that you cannot use rPlot in this case.

#this works
p1 <- rPlot(x='Date', y='Amount', data = rawData, type = 'line')
p1

It seems to me that if you want to plot a barchart the best thing is to use the vPlot (or hPlot for a horizontal bar) function which works fine:

p1 <- vPlot(x='Date', y='Amount', data = rawData, type = 'bar')
p1

enter image description here

And actually as per @Shiva 's message below you can also do (type = 'column' will print it vertically):

hPlot(x='Date', y='Amount', data = rawData, type = 'column')

Which actually looks even better:

enter image description here

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • Ah, I see. Where are vPlot and hPlot from? They don't seem to be part of the rCharts package.. – user1357015 Jul 05 '15 at 02:40
  • Both are from the `rCharts` package. `rCharts` is installed from github and it is not documented properly unfortunately... If you type `vPlot` or `hPlot` on your console, you will see the `` at the bottom of the source code. `> vPlot function (x, y, data, type, ...) { def_spec <- get_def_spec(type) vChart <- Vega$new(def_spec) params_ <- getLayer(x, y, data, type, ...) data_values <- toJSONArray(fixLayerVega(params_)$data, json = F) vChart$data_values(data_values) return(vChart) } ` – LyzandeR Jul 05 '15 at 03:28
  • or type `ls(package:rCharts)` on your console which will show all of the functions in the `rCharts` package. Both `vPlot` and `hPlot` are in there. – LyzandeR Jul 05 '15 at 13:34
  • 1
    You can get vertical bars in hPlot too. Just use `column` in place of `bar` `hPlot(x='Date', y='Amount', data = rawData, type = 'column')` – Shiva Jul 07 '15 at 02:46
  • @Shiva Thanks for the comment. Learnt something new today :) – LyzandeR Jul 07 '15 at 08:36
  • @LyzandeR I have seen bar plots using rPlot too... I am not sure why it doesn't work here... The following is a working example ! `> data (HairEyeColor) > hair_eye = as.data.frame(HairEyeColor) > rPlot(Freq ~ Hair | Eye, color = 'Eye', data = hair_eye, type = 'bar' )` – Shiva Jul 07 '15 at 12:53