r - 连续数据的千层面图
问题描述
此代码适用于分类数据
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)])
推荐阅读
- javascript - 如何终止事件源侦听器
- javascript - 如何引用此 JSON 对象数据?
- tensorflow - 深度学习模型 (LSTM) 预测相同的类别标签
- php - 来自 wamp 服务器上的 php api 的本机 403 权限错误反应
- java - JPA 一对一递归映射
- c# - Unity - 即使不按任何东西,角色也不会停止移动
- python - 记下 discord bot 的 TokenID 会提示运行时错误
- javascript - Javascript 正则表达式匹配文档块内的 JSDoc 标签
- angular - 是否有防弹方法来确保使用 Capacitor Splash Screen 插件不显示白屏?
- c# - 如何在 c#、asp.net 中使用 post/get 将几个参数移交给服务器