连续数据的千层面图
Lasagna plot for continuous data
此代码适用于分类数据
library(longCatEDA)
library(colorspace)
set.seed(642531)
y <- matrix(sample(1:24, 500, replace=TRUE), 100, 5)
set.seed(963854)
times <- matrix(runif(600, 1, 3), 100, 6)
# times must be cumulative
times <- t(apply(times, 1, cumsum))
lc <- longCat(y, times=times)
par(mfrow=c(1,1), bg='white', mar=c(5.1, 4.1, 4.1, 10.1), xpd=TRUE)
cols <- longCatPlot(lc, colScheme='heat', legendBuffer=0, groupBuffer=0,main='Individually test Varying Times of Observation')
legend(15.5, 100, legend=lc$Labels, lty=1, col=cols, lwd=2)
但是如图所示,如果我有很多类别(超过10个),图例应该是连续刻度而不是24个类别。
在 longCatEDA
库中,他们建议在这种情况下使用 longContPlot
,我正在尝试这样的事情:
longContPlot(lc, times, jog=TRUE, main='Individually varying times', ylab='', xlab='Days')
但是没用..
不确定如何在 longCatEDA
中执行此操作,但在 plotrix 中使用 color.legend
函数这很容易:
library(colorspace)
library(plotrix)
set.seed(642531)
y <- matrix(sample(1:24, 500, replace=TRUE), 100, 5)
set.seed(963854)
times <- matrix(runif(600, 1, 3), 100, 6)
# times must be cumulative
times <- t(apply(times, 1, cumsum))
lc <- longCat(y, times=times)
par(mfrow=c(1,1), bg='white', mar=c(5.1, 4.1, 4.1, 10.1), xpd=TRUE)
cols <- longCatPlot(lc, colScheme='heat', legendBuffer=0, groupBuffer=0,main='Individually test Varying Times of Observation')
plotrix::color.legend(xl=par('usr')[1]+1.05*(par('usr')[2]-par('usr')[1]),
xr=par('usr')[1]+1.15*(par('usr')[2]-par('usr')[1]),
yb=par('usr')[3]+0.20*(par('usr')[4]-par('usr')[3]),
yt=par('usr')[3]+0.80*(par('usr')[4]-par('usr')[3]),
rect.col = cols,gradient="y",
legend = lc$Labels[seq(1,length(lc$Labels),3)])
此代码适用于分类数据
library(longCatEDA)
library(colorspace)
set.seed(642531)
y <- matrix(sample(1:24, 500, replace=TRUE), 100, 5)
set.seed(963854)
times <- matrix(runif(600, 1, 3), 100, 6)
# times must be cumulative
times <- t(apply(times, 1, cumsum))
lc <- longCat(y, times=times)
par(mfrow=c(1,1), bg='white', mar=c(5.1, 4.1, 4.1, 10.1), xpd=TRUE)
cols <- longCatPlot(lc, colScheme='heat', legendBuffer=0, groupBuffer=0,main='Individually test Varying Times of Observation')
legend(15.5, 100, legend=lc$Labels, lty=1, col=cols, lwd=2)
但是如图所示,如果我有很多类别(超过10个),图例应该是连续刻度而不是24个类别。
在 longCatEDA
库中,他们建议在这种情况下使用 longContPlot
,我正在尝试这样的事情:
longContPlot(lc, times, jog=TRUE, main='Individually varying times', ylab='', xlab='Days')
但是没用..
不确定如何在 longCatEDA
中执行此操作,但在 plotrix 中使用 color.legend
函数这很容易:
library(colorspace)
library(plotrix)
set.seed(642531)
y <- matrix(sample(1:24, 500, replace=TRUE), 100, 5)
set.seed(963854)
times <- matrix(runif(600, 1, 3), 100, 6)
# times must be cumulative
times <- t(apply(times, 1, cumsum))
lc <- longCat(y, times=times)
par(mfrow=c(1,1), bg='white', mar=c(5.1, 4.1, 4.1, 10.1), xpd=TRUE)
cols <- longCatPlot(lc, colScheme='heat', legendBuffer=0, groupBuffer=0,main='Individually test Varying Times of Observation')
plotrix::color.legend(xl=par('usr')[1]+1.05*(par('usr')[2]-par('usr')[1]),
xr=par('usr')[1]+1.15*(par('usr')[2]-par('usr')[1]),
yb=par('usr')[3]+0.20*(par('usr')[4]-par('usr')[3]),
yt=par('usr')[3]+0.80*(par('usr')[4]-par('usr')[3]),
rect.col = cols,gradient="y",
legend = lc$Labels[seq(1,length(lc$Labels),3)])