Google Vis时间线聚合 [英] Google Vis Timeline aggregation

查看:213
本文介绍了Google Vis时间线聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能修改这段代码在时间轴上有一个聚合视图?



我不想为鳄梨有三条不同的线。我想只有一条线用于鳄梨存在时。我甚至希望为整个数据添加一行,而不是说一个完整的鳄梨油生产线,一个完整的草莓生产线和一个完整的蓝莓生产线。任何想法真的很感激。

另外,任何想法如何正确显示那些时间?每两次之间的差异小于一秒,但是以年度衡量。

  library(googleViz)
dd< - read.csv(header = TRUE,text =rosbagTimestamp ,数据
1438293919014802388,鳄梨
1438293919078955343,鳄梨
1438293919082352685,牛油果
1438293919146142553,0
1438293919177955753,0
1438293919244013175,草莓
1438293919251252990,草莓
1438293919322521358,蓝莓
1438293919327731275,蓝莓)

dd < - 内(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鳄梨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 2015-08-30 12:10:40 2015-07-30 18:05:19
#6草莓1977-09-25 01:24:16 2015-07-30 18:05:19
#7草莓1977-12-17 19:29:52 2015-07-30 18:05 :19
#8蓝莓1980-03-21 16:15:44 2015-07-30 18:05:19
#9蓝莓1980-05-21 00:26:40 2015-07- 30 18:05:19

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

解决方案

b

  library('googleVis')
dd < - read.csv(header = TRUE,text =rosbagTimestamp,数据
1438293919014802388,鳄梨
1438293919078955343,鳄梨
1438293919082352685,牛油果
1438293919146142553,0
1438293919177955753,0
1438293919244013175,草莓
1438293919251252990,草莓
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
})

##按时间分组
dd1 < - 聚集(。 (dd1,{
start< - as.POSIXct(start,origin ='1970-01-01'))
(数据,数据= dd,总和)
dd1 <结束< - 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鳄梨1969-12-31 19:00:01 1969-12-31 19:00:43
#3蓝莓1969 -12-31 19:00:06 1969-12-31 19:00:28
#4草莓1969-12-31 19:00:04 1969-12-31 19:00:28

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


How can I modify this code to have an aggregated view in the timeline?

I don't want to have three different lines just for avocado. I want to have one line just for when avocado exists. Preferably I even want to have one line for the whole data rather than say one complete line for avocado, one complete line for strawberry and one complete line for blueberry. Any idea is really appreciated.

Besides, any idea how to show those time correctly? The differences between each two time is less than a second but what is shown in measured in year.

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

解决方案

You just need to divide by the appropriate magnitude and choose your favorite aggregation tool to add the times by group (if I understand you correctly)

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

这篇关于Google Vis时间线聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆