getEventRelations: Begin/End Relations between Events

View source: R/eventRelation.R

getEventRelationsR Documentation

Begin/End Relations between Events

Description

relations between begin and end of events

Usage

getEventRelations(
  events,
  referenceName,
  partnerName,
  parallelEventInfo = NULL,
  dbg = TRUE
)

Arguments

events

list of event lists (in a data frame), as e.g. returned by getEventsWithStatisticsForMultipleSeries

referenceName

name of column in parallelEventInfo containing the numbers of the events to which the events in column partnerName are to be compared.

partnerName

name of column in parallelEventInfo containing the numbers of the events which are compared to the events in column partnerName.

parallelEventInfo

data frame as returned by getParallelEventsInfo. If NULL, events must be specified.

dbg

if TRUE, debug messages are shown.

Examples

# Load example data set containing a list of rain events at different gauges
data(rainEvents)
  
cat(sprintf(
  "Event lists available for: %s\n", 
   paste(names(rainEvents), collapse = ", ")
))
  
# How are rain events in BlnX related to rain events in Wil?
eventRelations <- getEventRelations(
  events = rainEvents, 
  referenceName = "BlnX", 
  partnerName = "Wil"
)
  
# Let's have a look at the output
eventRelations
  
# Example 1: partner events that are fully containing the reference events
isContaining <- eventRelations$beginRelation == "beginsBefore" & 
eventRelations$endRelation == "endsAfter"
  
# The following table relates numbers of "partner" events (event2) to numbers
# of "reference" events (event1) for each case in which a reference event is
# fully contained in a partner event.
containing <- eventRelations[isContaining, ]
  
# Let's check this graphically:
  
# Define plot matrix of two rows and one column
old.par <- graphics::par(mfrow = c(2, 1))
  
ganttPlotEvents(
  events = rainEvents$BlnX[], 
  indicate = containing$event1, 
  ylim = c(1, 2.8), 
  title = "BlnX",
  indicationColour = "blue"  
)
  
ganttPlotEvents(
  rainEvents$Wil, 
  indicate = containing$event2, 
  add = TRUE, 
  y1 = 1.8, 
  title = "Wil"
)
  
graphics::title("Events at Wil (red), fully containing events at BlnX (blue)")
  
# Example 2: partner events that are starting before the reference event starts
# and ending before the reference event ends
isOverlappingLeft <- eventRelations$beginRelation == "beginsBefore" & 
eventRelations$endRelation == "endsBefore"
  
overlappingLeft <- eventRelations[isOverlappingLeft, ]
  
# Again, check this graphically:
ganttPlotEvents(
  events = rainEvents$BlnX[], 
  indicate = overlappingLeft$event1, 
  ylim = c(1, 2.8), 
  title = "BlnX",
  indicationColour = "blue"  
)
  
ganttPlotEvents(
  rainEvents$Wil, 
  indicate = overlappingLeft$event2, 
  add = TRUE, 
  y1 = 1.8, 
  title = "Wil"
)
  
graphics::title(paste(
  "Events at Wil (red), starting before the start and ending before",
  "the end\nof the events at BlnX (blue)"
))
  
# Reset graphical parameters
graphics::par(old.par)  
  

KWB-R/kwb.event documentation built on June 14, 2022, 1:15 p.m.