plotTimeSeriesLab plots line charts of laboratory data.

plotTimeSeriesLab(
  labData,
  idColName,
  labItemColName,
  timeMarkColName,
  valueColName,
  timeStart = NULL,
  timeEnd = NULL,
  abnormalMarkColName = NULL
)

Arguments

labData

a file or dataframe of laboratory test data with at least 4 columns about patient ID, lab item, test value and test date, respectively.

idColName

the column name that records patient ID in labData.

labItemColName

the column name that records lab item in labData. If lab code is combined by multiple columns, then just simply add + operator between column names, e.g., A + B.

timeMarkColName

the column name that records time in labData. Time can be time window or be real date.

timeStart

any starting time point of interesting. It can be time window or be real date depending on the selection of timeMarkColName.

timeEnd

any ending time point of interesting. It can be time window or be real date depending on the selection of timeMarkColName.

abnormalMarkColName

the column name that records abnormal mark in labData. It is optional.

Value

One or multiple line chart of temoral laboratory results of one or multiple patient(s).

Details

This function provides an overview and temporal changes of laboratory tests. If abnormalMarkColName provided, then "H" mark is displayed by "▲" icon. Similarly, "L" mark is displayed by "▽" icon. Time mark can be continuous or discrete, but labData should be longitudinal.

Examples


timeSeriesData <- getTimeSeriesLab(labData = labSample,
                                   idColName = SUBJECT_ID,
                                   labItemColName = ITEMID,
                                   dateColName = CHARTTIME,
                                   valueColName = VALUENUM,
                                   indexDate = first,
                                   gapDate = 30,
                                   completeWindows = TRUE)
timeSeriesPlot <-plotTimeSeriesLab(labData = timeSeriesData,
                                   idColName = ID,
                                   labItemColName = ITEMID,
                                   timeMarkColName = Window,
                                   valueColName = Nearest,
                                   timeStart = 1,
                                   timeEnd  = 5,
                                   abnormalMarkColName = NULL)
plot(timeSeriesPlot)
#> geom_path: Each group consists of only one observation. Do you need to adjust
#> the group aesthetic?
#> Warning: Removed 66 rows containing missing values (geom_point).

# With abnormal mark
loincSample <- mapLOINC(labData = labSample,
                       labItemColName = ITEMID,
                       mappingTable = mapSample)
timeSeriesDataLOINC <- getTimeSeriesLab(labData = loincSample,
                                  idColName = SUBJECT_ID,
                                  labItemColName = LOINC + LABEL,
                                  dateColName = CHARTTIME,
                                  valueColName = VALUENUM,
                                  indexDate = first,
                                  gapDate = 30,
                                  completeWindows = TRUE)
colnames(patientSample)[2]<-"ID"
timeSeriesDataMarked <- getAbnormalMark(labData = timeSeriesDataLOINC,
                                       idColName = ID,
                                       labItemColName = LOINC,
                                       valueColName = Nearest,
                                       genderColName = GENDER,
                                       genderTable = patientSample,
                                       referenceTable = refLOINC)

timeSeriesPlotMarked <- plotTimeSeriesLab(labData = timeSeriesDataMarked,
                                         idColName = ID,
                                         labItemColName = LOINC + LABEL,
                                         timeMarkColName = Window,
                                         valueColName = Value,
                                         timeStart = 1,
                                         timeEnd = 5,
                                         abnormalMarkColName = ABMark)
plot(timeSeriesPlotMarked)
#> geom_path: Each group consists of only one observation. Do you need to adjust
#> the group aesthetic?
#> Warning: Removed 50 rows containing missing values (geom_point).