【问题标题】:R Corrplot: change color of column text labels but not row text labelsR Corrplot:更改列文本标签的颜色,但不更改行文本标签
【发布时间】:2018-09-04 15:03:11
【问题描述】:

我正在使用corrplot 函数创建 4 个 x 变量和 12 个 y 变量的 beta 系数的可视化。以下是我目前使用的代码:

library(corrplot)
corrplot(beta_m, is.corr=FALSE, method="square", 
     tl.srt=65, tl.cex=0.95, number.cex=0.8, tl.col='black', cl.length 
= 5, cl.align="l")

这是它来自的数据:

beta_m<-structure(c(0, 0, -0.584090272222348, 0, 0, 0.11291756016558, 
-0.435893170100887, 0, 0, 0, -0.460227704153223, 0, 0, 
0.222130737988377, 
0, 0.0974747494000928, 0, 0.117470450053172, -0.723935606930726, 
0, -0.308146541461676, 0, 0, 0, 0, 0.153128826514138, 0, 0, 0, 
0, -0.360425453158442, 0, 0, 0, -0.508415520561608, 0, 
-0.303599419688516, 
0, 0, 0, 0, 0, -0.551430826126704, 0, 0, 0, 0, 0), .Dim = c(4L, 
12L), .Dimnames = list(c("Sex: Female", "Age", "IM: MVA", "LOC 
duration: < 5 min"
), c("PDGF", "$ paste(MIP-1,beta)", "$ paste(TNF,-alpha)", "IP-10", 
"Eotaxin", "FGF-basic", "IL-1ra", "IL-9", "MCP-1", "IL-17A", 
"IL-8", "$ paste(IFN,gamma)")))

这就是它目前的样子:

我需要的是一些列标签(顶部的 12 个标签)是不同的颜色,而 4 个行标签保持黑色。 tl.col 参数同时改变行和列标签的颜色。

编辑:如果某些列标签是粗体而其他不是,它也可以工作。

【问题讨论】:

    标签: r plot r-corrplot


    【解决方案1】:

    一个解决方案是这样的:

    1. 绘制所有标签变为tl.col="red"的图片。
    2. beta_m 中删除您希望保持红色的列名。
    3. 在顶部添加第二张带有tl.col="black" 的图片。

    这是一个演示:

    corrplot(beta_m, is.corr=FALSE, method="square", tl.srt=65, tl.cex=0.95, number.cex=0.8,
             tl.col='red', cl.length = 5, cl.align="l")
    
    colnames(beta_m)[5:7] <- ""
    
    corrplot(beta_m, is.corr=FALSE, method="square", tl.srt=65, tl.cex=0.95, number.cex=0.8,
             tl.col='black', cl.length = 5, cl.align="l", add=TRUE)
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      • 2022-08-08
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多