We are monitoring 3 processes A, B and C that will always either be in level X, Y, or Z. A protocol records when a process changes levels.
df = read.csv(tc <- textConnection('Time1,Process1,Level1 2013-01-09 18:00:34,A,X 2013-01-09 18:00:34,B,Y 2013-01-09 18:00:34,C,X 2013-01-09 18:00:59,A,Z 2013-01-09 18:01:06,A,X 2013-01-09 18:01:10,C,Y 2013-01-09 18:01:10,B,Z 2013-01-09 18:01:13,A,Z 2013-01-09 18:01:18,A,Off 2013-01-09 18:01:18,B,Off 2013-01-09 18:01:18,C,Off '),header=TRUE) close.connection(tc) df$Time1 = as.POSIXct(df$Time1)
Monitoring was started at 18:00:34 and switched off at 18:01:18. Between 18:00:34 and 18:00:59 process A was in level X, between 18:00:59 and 18:01:06 process A was in level Z.
We would like to show on the x-axis the continuous interval between 18:00:34 and 18:01:18, and three horizontal bars (A, B, C) of equal width that indicate the current process level at the time shown on the x-axis.
Below what we tried last. The overall structure of the chart seems right, but the Time-axis does not make much sense and data is also missing. (We don't need the Off category but it's probably easy to cut it out once the Time-axis makes sense.) Any guidance would be much appreciated.
ggplot() + geom_bar(data=df, aes(x=Process1, y=Time1, fill=Level1)) + coord_flip()
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/oekLX.jpg" data-original="https://i.stack.imgur.com/oekLX.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />Answer1:
I'm not sure about using
geom_bar to do this, but I can get
geom_line to do something similar if I increase the size of the lines.
library(ggplot2) library(scales) ggplot(df, aes(x=Time1, y=Process1, group=Process1, colour=Level1)) + geom_line(size=5) + scale_x_datetime("", labels = date_format("%H:%M:%S"))
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/GaZiU.png" data-original="https://i.stack.imgur.com/GaZiU.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />