You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用longCatEDA包绘制千层面图如何自定义红黄绿三色配色

自定义千层面图配色解决方案

longCatPlot函数支持直接传入自定义颜色向量,优先级高于内置colScheme参数,只需按你需要的分类顺序定义配色即可实现需求,无需额外依赖第三方调色板,修改后的完整可运行代码如下:

library(longCatEDA)
library(colorspace)
library(RColorBrewer)
set.seed(642531)
y <- matrix(sample(1:3, 500, replace=TRUE), 100, 5)
set.seed(963854)
times <- matrix(runif(600, 1, 3), 100, 6)

# times必须为累计值
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)

# 按分类1红、分类2黄、分类3绿的顺序定义自定义配色,也可替换为十六进制颜色码实现更精细的颜色调整
custom_cols <- c("red", "yellow", "green")
# 绘图时传入自定义配色即可
longCatPlot(lc, col = custom_cols, legendBuffer=0, groupBuffer=0, main='自定义配色千层面图')

# 图例同步使用自定义配色
legend(16.5, 100, legend=lc$Labels, lty=1, col=custom_cols, lwd=2)

千层面图示例

内容的提问来源于stack exchange,提问作者Ana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 04:09:03