我正在尝试使用 ggplot2 制作多面 t 图表,其中 x 轴表示事件序列,y 轴表示这些事件之间的天数。x 轴应标有事件日期,但它不是时间序列,因为无论事件之间的实时时间如何,x 轴刻度之间的距离应该是统一的。
添加刻面层一直让我感到困惑。这是一些示例数据:
df <- data.frame(EventDT = as.POSIXct(c("2014-11-22 07:41:00", "2015-02-24 08:10:00",
"2015-06-10 13:54:00", "2015-07-11 02:43:00",
"2015-08-31 19:08:00", "2014-11-18 14:06:00",
"2015-06-09 23:10:00", "2016-02-29 07:55:00",
"2016-05-22 04:30:00", "2016-05-25 21:46:00",
"2014-12-22 16:19:00", "2015-05-13 16:38:00",
"2015-06-01 09:05:00", "2016-02-21 02:30:00",
"2016-05-13 01:36:00")),
EventNBR = rep(1:5, 3),
Group = c(rep('A', 5), rep('B',5), rep('C',5)),
Y = c(15.818750, 94.020139, 106.238889, 30.534028, 51.684028,
187.670139, 203.377778, 264.364583, 82.857639, 3.719444,
169.829861, 142.013194, 18.685417, 264.725694,81.962500))
Run Code Online (Sandbox Code Playgroud)
忽略事件的日期,我可以生成以下内容:
g <- ggplot(df, aes(x=EventNBR, y=Y)) +
geom_point() + …Run Code Online (Sandbox Code Playgroud)