【问题标题】:Personalize colors in lasagna plot using longCatEDA使用 longCatEDA 个性化千层面图中的颜色
【发布时间】:2021-08-17 06:55:54
【问题描述】:

可以使用此代码绘制具有 3 个分类变量的千层面图并且工作正常

[![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 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='rainbow', legendBuffer=0, groupBuffer=0,main='How to personalize colors?')

legend(16.5, 100, legend=lc$Labels, lty=1, col=cols, lwd=2)][1]][1]

但我正在尝试个性化颜色:

1.红色

2.黄色

3.绿色

我找不到如何使用特定颜色,所以我尝试了默认调色板,我能做的最好的就是使用“彩虹”方案。 还有colorspaceRColorBrewer,但没有一个包括我需要的3种颜色(按顺序红、黄、绿)

【问题讨论】:

    标签: r plot categorical-data longitudinal


    【解决方案1】:

    不要使用colScheme-参数,而是使用cols

    library(longCatEDA)
    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 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, cols = c("red", "yellow", "green"), legendBuffer=0, groupBuffer=0,main='How to personalize colors?')
    
    legend(16.5, 100, legend=lc$Labels, lty=1, col=c("red", "yellow", "green"), lwd=2)
    

    reprex package (v2.0.1) 于 2021-08-17 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 2021-02-09
      • 2016-08-02
      • 2017-01-23
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多