首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连续数据的千层面图

连续数据的千层面图
EN

Stack Overflow用户
提问于 2021-08-16 13:42:47
回答 1查看 47关注 0票数 0

此代码适用于分类数据

代码语言:javascript
复制
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个类别。在他们推荐在这种情况下使用longContPlotlongCatEDA库中,我尝试如下所示:

代码语言:javascript
复制
longContPlot(lc, times, jog=TRUE, main='Individually varying times', ylab='', xlab='Days')

但是它不起作用..

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-16 14:18:49

不确定如何在longCatEDA中执行此操作,但在plotrix中使用color.legend函数非常简单:

代码语言:javascript
复制
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)])

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68803853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档