Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
直方图跟踪R中的库存水平_R_Histogram - Fatal编程技术网

直方图跟踪R中的库存水平

直方图跟踪R中的库存水平,r,histogram,R,Histogram,我正在寻找一种方法来可视化一天的库存。数据集如下所示,最后两列的摘要如下: 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

我正在寻找一种方法来可视化一天的库存。数据集如下所示,最后两列的摘要如下:

                 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
存货

 Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1120.00   -98.75     9.00     0.00   100.00  1988.00 
持续时间

Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
 0.00     40.25    205.50   2100.00    529.00 272700.00 
我想通过显示在不同库存水平上花费了多少时间来可视化数据。您会推荐什么作为此功能?到目前为止,我只找到了基于频率的直方图,而不是基于时间的直方图。我的预期结果与此类似:


提前感谢

我根据自己的需要编写了以下函数。希望能有帮助

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

inv.barplot.IDs我根据需要编写了以下函数。希望能有帮助

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

inv.barplot.IDs您可以尝试以下操作:
barplot(属性表(表(df$Inventroy,df$Duration)),旁边=T)
您可以尝试以下操作:
barplot(属性表(表(df$Inventroy,df$Duration)),旁边=T)