mtb: Time Related Plots"

  collapse = TRUE,
  comment = "#>"


It's common to have observations that were measured longitudinally. Here are some functions that could present observations measured over time.

How to use - plot event periods with grouped labels

This is a basic example which shows you how to plot intervals of events with group labels at the beginning of individual intervals.

dt = data.frame( id=paste('ID', c(seq(1,5), seq(1,5)),sep=""), idn=c(seq(1,5),seq(1,5)), start=1800*seq(1,10)/3, end=1800*(seq(1,10)/3+seq(2,-2)), label=rep(c('A','B'),5) )
p=time_plot_interval( dt, xlab='Time', ylab='ID', legend_title='Group', arrow_wt=2, arrow_color='gray')

How to use - create a static timeline plot

There is an existing function vistime::gg_vistime() that creates plots for time periods or single time points. There is also an article by Ben Alex Keen that uses ggplot2 for plotting a series of events.

The time_plot_event() function creates a simplified timeline plot.

dt = data.frame( id=c(rep('Sous Chef',3), rep('Both',3), rep('Chef',4)), idn=c(rep(1,3),rep(-1,3), rep(2,4)), start=1800*c(0,1,2, 0.5, 1.2, 3, 1,2,3,4), end=1800*c(3.5,NA,3, 2, 6, NA, 2,3.5,3, 3.5),
label=c('Turkey', 'Watch Temp', 'Gravy', 'Stuffing', 'Whipped Cream', 'Cookie', 'Cranberry', 'Potato', 'Green Bean', 'Pumpkin Pie'), labelend=c('', '', '~~?', '->>', 'not shown', '', '', '', '||', '->X'), color=c('Oven', 'Other', 'Stove','Oven','Other','Oven','Stove','Oven','Oven','Oven' ), type=c('b', 'p', 'i','i','p','p','p','b','i','i' ) )
time_plot_event( dt ) 

Note that the compact option can reduce the use of vertical spaces. However, to avoid reversed interval like event-10, the input data set should have start time < end time.

time_plot_event( dt, compact=TRUE )

Try the mtb package in your browser

Any scripts or data that you put into this service are public.

mtb documentation built on Oct. 21, 2022, 1:05 a.m.