1

我有以下数据并尝试使用hPlot

hPlot(Numbers~Date, data = df, group='Type', type = "line", radius=6)


     Date        Type      Numbers
 2014-01-05     Type-1          16
 2014-01-12     Type-1          82
 2014-01-12     Type-2           2
 2014-01-19     Type-1         177
 2014-01-26     Type-1         270
 2014-01-26     Type-2           3
 2014-02-02     Type-1         381
 2014-02-09     Type-1         461
 2014-02-09     Type-2           4

我将多个日期作为 x 轴,如下图所示。我也尝试过uniqueas.character但 x 数据与 y 数据不对应。

在此处输入图像描述

4

1 回答 1

3

这是您的问题的解决方案。您可以在此处查看图表和代码。我也在这里发布

# don't switch to scientific notation, since we want date to be
# represented in milliseconds
options(scipen = 13)
dat = transform(df, Date2 = as.numeric(as.POSIXct(Date))*1000)

library(rCharts)
h1 <- hPlot(Numbers ~ Date2, data = dat, 
  group = 'Type', 
  type = "line", 
  radius=6
)
h1$xAxis(type = 'datetime', labels = list(
  format = '{value:%Y-%m-%d}'  
))
h1
于 2014-03-02T04:26:46.137 回答