此代码适用于分类数据
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个类别。在他们推荐在这种情况下使用longContPlot的longCatEDA库中,我尝试如下所示:
longContPlot(lc, times, jog=TRUE, main='Individually varying times', ylab='', xlab='Days')但是它不起作用..
发布于 2021-08-16 14:18:49
不确定如何在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)])

https://stackoverflow.com/questions/68803853
复制相似问题