Spaghetti plot
Spaghetti plot for longitudinal data
spaghetti( formula, data = NULL, id = "id", group = NULL, type = "o", lty = 1, pch = NA, col = 1:10, alpha = 0.3, lwd = 1, level = 0.95, trend.formula = formula, tau = NULL, trend.lty = 1, trend.join = TRUE, trend.delta = 0.2, trend = !is.null(tau), trend.col = col, trend.alpha = 0.2, trend.lwd = 3, trend.jitter = 0, legend = NULL, by = NULL, xlab = "Time", ylab = "", add = FALSE, ... )
formula
: Formula (response ~ time)data
: data.frameid
: Id variablegroup
: group variabletype
: Type (line 'l', stair 's', ...)lty
: Line typepch
: Colourcol
: Colouralpha
: transparency (0-1)lwd
: Line widthlevel
: Confidence leveltrend.formula
: Formula for trendlinetau
: Quantile to estimate (trend)trend.lty
: Trend line typetrend.join
: Trend polygontrend.delta
: Length of limit barstrend
: Add trend linetrend.col
: Colour of trend linetrend.alpha
: Transparencytrend.lwd
: Trend line widthtrend.jitter
: Jitter amountlegend
: Legendby
: make separate plot for each level in 'by' (formula, name of column, or vector)xlab
: Label of X-axisylab
: Label of Y-axisadd
: Add to existing device...
: Additional arguments to lower level argumentsif (interactive() & requireNamespace("mets")) { K <- 5 y <- "y"%++%seq(K) m <- lvm() regression(m,y=y,x=~u) <- 1 regression(m,y=y,x=~s) <- seq(K)-1 regression(m,y=y,x=~x) <- "b" N <- 50 d <- sim(m,N); d$z <- rbinom(N,1,0.5) dd <- mets::fast.reshape(d); dd$num <- dd$num+3 spaghetti(y~num,dd,id="id",lty=1,col=Col(1,.4), trend.formula=~factor(num),trend=TRUE,trend.col="darkblue") dd$num <- dd$num+rnorm(nrow(dd),sd=0.5) ## Unbalance spaghetti(y~num,dd,id="id",lty=1,col=Col(1,.4), trend=TRUE,trend.col="darkblue") spaghetti(y~num,dd,id="id",lty=1,col=Col(1,.4), trend.formula=~num+I(num^2),trend=TRUE,trend.col="darkblue") }
Klaus K. Holst