R中以时间为导向的围巾情节?

I have time-oriented data that I would like to make into a scarf plot. In fact, I believe my data is almost identical to this question: 1. I have tried to recreate it based on the comments there, but the original CSV file is not available anymore and my attempts to recreate the data and plot have failed. I assume the original CSV is formatted differently than mine. I'm just learning R, so that doesn't help either. I don't believe I can do this in MATLAB, which is my preferred language.

下面的示例数据与我正在使用的相似。

trial,event,time,time2

A,1,0,0.1

A,3,0.1,0.3

A,2,0.3,0.5

A,3,0.5,0.8

A,1,0.8,1

时间已归一化,因此它始终从t = 0到t = 1,但是行数在两次试验之间可能会有所不同。事件总是一次发生,永远不会重叠。我将一次比较2个试验,但从一个试验开始,直到可以进行绘制。

> library(readxl)
> library(ggplot2)
> example <- read_excel("C:/Users/~/Desktop/~/example.xlsx")
> example$trial <- factor(example$trial)
> example$event <- factor(example$event)
> example$time2 <- c(0, diff(example$time))
> ggplot(example, aes(x = trial, y = time2, fill = event)) + geom_bar(stat = "identity") + coord_flip()

给我下面的图表,它只是一个标准的条形图,其中包含每个事件的持续时间。先前的答案显示了我想要的行为,它是每个事件发生时的面向时间的“图片”。

Plot

评论