rChart给出一个空白屏幕

时间:2015-07-04 22:44:56

标签: r rcharts

这是我的数据:

    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))

以下是空白:

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

我不知道为什么 - 我是rCharts的新手 - 我通常使用ggplot2。

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

我已经看到了很多关于rCharts的教程或博客,并且没有rPlotbar类型一起使用的示例,其中数据集类似于您的(有)只有一个here,但它被用作带有分箱变量的直方图和不相同的计数。

如果您将rPlot类型更改为bar,则line功能正常工作,这让我觉得在这种情况下您无法使用rPlot

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

在我看来,如果您想绘制条形图,最好的方法是使用vPlot(或hPlot作为水平条)功能,该功能正常:

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

enter image description here

实际上根据@Shiva的消息,你也可以这样做(type ='column'将垂直打印):

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

实际上看起来更好:

enter image description here