Google Vis时间线聚合

Google Vis Timeline aggregation

如何修改此代码以在时间轴中显示聚合视图?

我不想仅仅为了鳄梨就拥有三种不同的生产线。我只想在鳄梨存在时使用一行。最好我什至想用一行来表示整个数据,而不是说一行完整的鳄梨、一行完整的草莓和一行完整的蓝莓。任何想法真的很感激。

此外,知道如何正确显示这些时间吗?每两次之间的差异小于一秒,但以年份显示。

library("googleViz")
dd <- read.csv(header = TRUE, text = "rosbagTimestamp,data
1438293919014802388,avocado
1438293919078955343,avocado
1438293919082352685,avocado
1438293919146142553,0
1438293919177955753,0
1438293919244013175,strawberry
1438293919251252990,strawberry
1438293919322521358,blueberry
1438293919327731275,blueberry")

dd <- within(dd, {
  end <- as.POSIXct(as.numeric(substr(rosbagTimestamp, 1, 10)),
                    origin = '1970-01-01')
  start <- as.POSIXct(as.numeric(substr(rosbagTimestamp, 11, 19)),
                      origin = '1970-01-01')
  rosbagTimestamp <- NULL
})

#         data               start                 end
# 1    avocado 1970-06-21 03:47:12 2015-07-30 18:05:19
# 2    avocado 1972-07-02 16:01:04 2015-07-30 18:05:19
# 3    avocado 1972-08-10 23:44:00 2015-07-30 18:05:19
# 4          0 1974-08-19 07:07:44 2015-07-30 18:05:19
# 5          0 1975-08-22 12:10:40 2015-07-30 18:05:19
# 6 strawberry 1977-09-25 01:24:16 2015-07-30 18:05:19
# 7 strawberry 1977-12-17 19:29:52 2015-07-30 18:05:19
# 8  blueberry 1980-03-21 16:15:44 2015-07-30 18:05:19
# 9  blueberry 1980-05-21 00:26:40 2015-07-30 18:05:19

plot(gvisTimeline(dd, rowlabel = 'data', barlabel = 'data',
                  start = 'start', end = 'end'))

你只需要除以合适的量级,然后选择你喜欢的聚合工具将时间分组相加(如果我没理解错的话)

library('googleVis')
dd <- read.csv(header = TRUE, text = "rosbagTimestamp,data
               1438293919014802388,avocado
               1438293919078955343,avocado
               1438293919082352685,avocado
               1438293919146142553,0
               1438293919177955753,0
               1438293919244013175,strawberry
               1438293919251252990,strawberry
               1438293919322521358,blueberry
               1438293919327731275,blueberry")

dd <- within(dd, {
  end <- as.POSIXct(as.numeric(substr(rosbagTimestamp, 1, 10)) / 1e8,
                    origin = '1970-01-01')
  start <- as.POSIXct(as.numeric(substr(rosbagTimestamp, 11, 19)) / 1e8,
                      origin = '1970-01-01')
  rosbagTimestamp <- NULL
})

## sum the times by group
dd1 <- aggregate(. ~ data, data = dd, sum)
dd1 <- within(dd1, {
  start <- as.POSIXct(start, origin = '1970-01-01')
  end <- as.POSIXct(end, origin = '1970-01-01')
})

#         data               start                 end
# 1          0 1969-12-31 19:00:03 1969-12-31 19:00:28
# 2    avocado 1969-12-31 19:00:01 1969-12-31 19:00:43
# 3  blueberry 1969-12-31 19:00:06 1969-12-31 19:00:28
# 4 strawberry 1969-12-31 19:00:04 1969-12-31 19:00:28

plot(gvisTimeline(dd1, rowlabel = 'data', barlabel = 'data',
                  start = 'start', end = 'end'))