首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >直方图跟踪库存水平(R)

直方图跟踪库存水平(R)
EN

Stack Overflow用户
提问于 2016-12-13 15:54:34
回答 1查看 72关注 0票数 1

我正在寻找一种方法,以形象化库存的整个一天。数据集如下所示,最后两列的摘要如下:

代码语言:javascript
复制
                 Time  Price Inventory Duration
1 9/1/2016 9:25:06 AM 13.960    318        0
2 9/1/2016 9:36:42 AM 13.980    106      696
3 9/1/2016 9:40:52 AM 13.990   -599      250
4 9/1/2016 9:52:54 AM 14.015     68      722
5 9/1/2016 9:52:54 AM 14.015    321        0
6 9/1/2016 9:54:17 AM 14.010     74       83

库存

代码语言:javascript
复制
 Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1120.00   -98.75     9.00     0.00   100.00  1988.00 

持续时间

代码语言:javascript
复制
Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
 0.00     40.25    205.50   2100.00    529.00 272700.00 

我想通过显示在不同的库存水平上花费了多少时间来可视化数据。对此,您推荐什么作为功能?到目前为止,我发现的只是基于频率的直方图,而不是时间。我的预期结果将类似于以下内容:

https://postimg.org/image/z074waij1/

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2017-01-05 12:47:04

我为我的需要编写了以下函数。希望它能帮上忙

代码语言:javascript
复制
inv.barplot.IDs <- function(inv.list, IDs = 1:1620)
  {
    # Subset according to the IDs
    myinvs <- as.data.frame(matrix(nrow = 0, ncol = 14))
    names(myinvs) <- inv.names
    Volume <- Duration <- vector("numeric")

    for (i in IDs)
    {
      #myinvs <- rbind(myinvs, inv.list[[i]])
      Volume <- c(Volume, as.numeric(inv.list[[i]]$Volume))
      Duration <- c(Duration, as.numeric(inv.list[[i]]$Duration))
    }

    # Design a sequence of skatules
    minimum <- min(Volume)
    maximum <- max(Volume)
    width <- (maximum + abs(minimum)) / 18
    width <- round(width, -1)
    seq.pos <- seq(width, maximum + width, by = width)
    seq.neg <- - seq(0, abs(minimum) + width, by = width)
    seq <- c(rev(seq.neg), seq.pos)

    # Categorize the dataframe (new column)
    Skatule <- numeric(length = length(Volume))
    for (i in 1:length(Volume))
    {
      Skatule[i] <- seq[head(which(seq > Volume[i]), 1) - 1]
    }

    barplot.data <- tapply(Duration, Skatule, sum)

    # Save the barplot
    #jpeg(filename = file.barplot, width = 480 * (16/9))
    inv.barplot <- barplot(barplot.data, border = NA, ylim = c(0, max(barplot.data)), main = "Total time spent on various inventory levels", xlab = "Inventory", ylab = "Log of Hours")
    #print(inv.barplot)
    #dev.off()
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41125272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档