2

我想为此使用 ggplot2 但不知道在哪里看。我有一个全局开始和结束时间min(begin)max(end)分别是我的 x 轴。我的 y 轴将是每个处理器,我的数据包括每个处理器的时间块,其中编译器将忙于编译或链接特定文件。我想查看处理器空闲的空白区域。我的 df 看起来像这样:

df <- data.frame(proc = as.factor(c('P_1', 'P_1', 'P_1', 'P_2', 'P_2', 'P_3')), begin=c(1, 20, 23 , 3, 5, 8), end=c(5, 19, 21, 4, 9, 100), what=c('compiling A', 'compiling B', 'linking A', 'compiling C', 'compiling D', 'compiling E'))
df
> df
  proc begin end        what
1  P_1     1   5 compiling A
2  P_1    20  19 compiling B
3  P_1    23  21   linking A
4  P_2     3   4 compiling C
5  P_2     5   9 compiling D
6  P_3     8 100 compiling E
> 

我怎样才能做到这一点?

4

1 回答 1

4

像这样的东西?

library(ggplot2)
ggplot(df, aes(x=begin, xend=end, y=proc, yend=proc, colour=what)) + 
  geom_segment(size=5)

在此处输入图像描述

于 2012-09-02T20:06:56.073 回答