简体   繁体   English

使用R中的ggplot的两个数据帧的多图和覆盖图

[英]Multi plot and overlay graphs for two dataframes using ggplot in R

I have data that I use to create two data frames: 我有用于创建两个数据框的数据:

#Event csv
timestamp,event
2013-04-03 22:59:05.061Z,A
2013-04-03 22:59:05.061Z,B
2013-04-03 22:59:07.109Z,C
2013-04-03 22:59:07.115Z,D
2013-04-03 22:59:07.209Z,E


# Performance data
hostname;interval;timestamp;CPU;user;nice;system;iowait;steal;idle
box1;1;2013-04-03 22:59:02 UTC;-1;10.53;0.00;2.01;0.50;0.00;86.97
box1;1;2013-04-03 22:59:03 UTC;-1;0.25;0.00;0.00;0.00;0.00;99.75
box1;1;2013-04-03 22:59:04 UTC;-1;0.00;0.00;0.25;0.25;0.00;99.50
box1;1;2013-04-03 22:59:05 UTC;-1;10.72;0.00;1.00;0.25;0.00;88.03
box1;1;2013-04-03 22:59:06 UTC;-1;10.67;0.00;10.67;0.00;0.25;78.41
box1;1;2013-04-03 22:59:07 UTC;-1;5.01;0.00;9.02;3.51;0.00;82.46
box1;1;2013-04-03 22:59:08 UTC;-1;12.28;0.00;11.53;4.26;0.25;71.68
box1;1;2013-04-03 22:59:09 UTC;-1;15.88;0.00;11.66;10.92;0.50;61.04

Now I am trying to plot these two dataframes using ggplot by overlaying data from events over performance data. 现在,我尝试通过将事件中的数据叠加到性能数据上来使用ggplot绘制这两个数据帧。

# This works
perfomance <- read.csv("performance.csv", header=TRUE,sep=";")
perfomance$timestamp <- as.POSIXlt(perfomance$timestamp)
p <- ggplot(data=performance, aes(x=timestamp, y=idle)) + geom_line()

Which produces 哪个产生

CPU闲置时间的图表

Now, getting to overlay the events data is problematic. 现在,要覆盖事件数据是有问题的。 Here's what I have tried 这是我尝试过的

> p + geom_point(data=events, aes(colour=factor(event)))
Error in eval(expr, envir, enclos) : object 'idle' not found

> p + geom_point(data=events, aes(colour=factor(event)), inherit.aes = FALSE)
Error: geom_point requires the following missing aesthetics: x, y

> p + geom_point(data=events, aes(x=timestamp, colour=factor(event)), inherit.aes = FALSE)
Error: geom_point requires the following missing aesthetics: y

How can I get some markers on the graph that show the events as an overlay? 如何在图形上获得一些标记,以将事件显示为叠加图? I don't care about their Y coordinate. 我不在乎他们的Y坐标。 I need them to be visible. 我需要它们可见。

使用geom_vline尝试这样的事情:

p + geom_vline(linetype=4, aes(colour=factor(event),xintercept = timestamp) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM