plotStream | R Documentation |
plotStream
makes a "stream plot" where each y
series is plotted as stacked filled polygons on
alternating sides of a baseline. A random wiggle is applied through the
arguments frac.rand
and spar
such that each plot will
be different unless preceeded by a random seed (e.g. set.seed(1)
).
plotStream( x, y, order.method = "as.is", frac.rand = 0.1, spar = 0.2, center = TRUE, ylab = "", xlab = "", border = NULL, lwd = 1, col = rainbow(length(y[1, ])), ylim = NULL, ... )
x |
A vector of values |
y |
A matrix of data series (columns) corresponding to x |
order.method |
Method of ordering y plotting order. One of the
following: |
frac.rand |
Fraction of the overall data "stream" range used to
define the range of random wiggle (uniform distrubution)
to be added to the baseline |
spar |
Setting for smooth.spline function to make a smoothed version of
baseline |
center |
Logical. If TRUE, the stacked polygons will be centered
so that the middle, i.e. baseline ( |
ylab |
y-axis labels |
xlab |
x-axis labels |
border |
Border colors for polygons corresponding to y columns (will recycle)
(see |
lwd |
Border line width for polygons corresponding to y columns (will recycle) |
col |
Fill colors for polygons corresponding to y columns (will recycle). |
ylim |
y-axis limits. If |
... |
Other plot arguments |
A plot with stream visualization added
#Create data set.seed(1) m <- 500 n <- 30 x <- seq(m) y <- matrix(0, nrow=m, ncol=n) colnames(y) <- seq(n) for(i in seq(ncol(y))){ mu <- runif(1, min=0.25*m, max=0.75*m) SD <- runif(1, min=5, max=20) TMP <- rnorm(1000, mean=mu, sd=SD) HIST <- hist(TMP, breaks=c(0,x), plot=FALSE) fit <- smooth.spline(HIST$counts ~ HIST$mids) y[,i] <- fit$y } y <- replace(y, y<0.01, 0) #Ex.1 : Color by max value) pal <- colorRampPalette(c(rgb(0.85,0.85,1), rgb(0.2,0.2,0.7))) BREAKS <- pretty(apply(y,2,max),8) LEVS <- levels(cut(1, breaks=BREAKS)) COLS <- pal(length(BREAKS )-1) z <- val2col(apply(y,2,max), col=COLS) #Plot order = "as.is" plotStream(x,y, xlim=c(100, 400), center=TRUE, spar=0.3, frac.rand=0.2, col=z, border="white", lwd=0.5) #Plot order = "max" plotStream(x,y, xlim=c(100, 400), center=TRUE, order.method="max", spar=0.3, frac.rand=0.2, col=z, border="white", lwd=0.5) #Ex. 2 : Color by first value ord <- order(apply(y, 2, function(r) min(which(r>0)))) y2 <- y[, ord] pal <- colorRampPalette(c("blue", "cyan", "yellow", "red")) z <- pal(ncol(y2)) #Plot order = "as.is" plotStream(x,y2, xlim=c(100, 400), center=FALSE, spar=0.1, frac.rand=0.05, col=z, border=1, lwd=0.25) #Plot order = "max" plotStream(x,y2, xlim=c(100, 400), center=FALSE, order.method="max", spar=0.1, frac.rand=0.05, col=z, border=1, lwd=0.25) #Extremely wiggly, no borders, no box, no axes, black background op <- par(bg=1, mar=c(0,0,0,0)) plotStream(x,y2, xlim=c(100, 400), center=FALSE, spar=0.3, frac.rand=1, col=z, border=NA, axes=FALSE) par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.