The santaR
package is
designed for the detection of significantly altered time trajectories
between study groups, in short time-series.
As the visualisation of significantly altered time-trajectories is
critical to the interpretation of the process under study, this vignette
will detail the plotting options present in santaR
.
santaR_plot()
returns a ggplot2 plotObject
that can be further modified using ggplot2
grammar.
First we can analyse a subset of data using
santaR_auto_fit()
, returning a list of
SANTAObj.
library(santaR)
# Load a subset of the example data
tmp_data <- acuteInflammation$data[,1:6]
tmp_meta <- acuteInflammation$meta
# Analyse data, with confidence bands and p-value
res_acuteInf_df5 <- santaR_auto_fit(inputData=tmp_data, ind=tmp_meta$ind, time=tmp_meta$time, group=tmp_meta$group, df=5, ncores=0, CBand=TRUE, pval.dist=FALSE)
## Input data generated: 0.01 secs
## Spline fitted: 0.06 secs
## ConfBands done: 5.99 secs
## total time: 6.06 secs
Each variable can be accessed either by its list position or variable name:
# Default plot
# individual points, individual trajectories, group mean curves and confidence bands
# access by list position
santaR_plot(res_acuteInf_df5[[5]])
The individual points, trajectories, group mean curves and confidence bands can be turned on or off:
# only groupMeanCurve
santaR_plot(res_acuteInf_df5$var_5, showIndPoint=FALSE, showIndCurve=FALSE, showGroupMeanCurve=TRUE, showConfBand=TRUE)
# only Individuals
santaR_plot(res_acuteInf_df5$var_5, showIndPoint=TRUE, showIndCurve=TRUE, showGroupMeanCurve=FALSE, showConfBand=FALSE)
Title and axis can be altered to suit the analysis:
# remove the legend
santaR_plot(res_acuteInf_df5$var_5, title='A variable, no legend', legend=FALSE)
santaR_plot()
returns a ggplot2 plotObject
that can be modified using all the range of ggplot2
grammar:
library(ggplot2)
# add x and y labels by adding it outside the plotting function [not useful but shows that any ggplot command can be added to the plot]
santaR_plot(res_acuteInf_df5$var_5, title='A variable') + xlab('Time') + ylab('Variable value')
# Constrain the x axis (will remove points and raise warnings)
santaR_plot(res_acuteInf_df5$var_5, showConfBand=FALSE, title='A variable', xlab='Time', ylab='Variable value') + xlim(0,48)
## Warning: Removed 4 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 4 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Removed 84 rows containing missing values or values outside the scale range
## (`geom_line()`).
Plots can be stored in a variables and combined in multiplots using
gridExtra grid.arrange()
:
library(gridExtra)
# store plot in a variable, plot multiple variables...
p1 <- santaR_plot(res_acuteInf_df5$var_3, title='First variable', xlab='Time', ylab='Variable value')
plot(p1)
p2 <- santaR_plot(res_acuteInf_df5$var_4, title='Second variable', xlab='Time', ylab='Variable value')
# multiplot
grid.arrange(p1, p2)
# Force both plots on the same y limits (remove legend from plots)
p1 <- santaR_plot(res_acuteInf_df5$var_3, title='First variable', xlab='Time', ylab='Variable value', legend=FALSE)
p2 <- santaR_plot(res_acuteInf_df5$var_4, title='Second variable', xlab='Time', ylab='Variable value', legend=FALSE)
p1 <- p1 + ylim(-1.2, 4.2)
p2 <- p2 + ylim(-1.2, 4.2)
grid.arrange(p1, p2, ncol=2 )