首页 > 解决方案 > Corrplot:不打印每个文本标签

问题描述

我正在使用他们的小插图中的示例,但实际上,我的相关矩阵要大得多,因此文本标签在图上不清晰。我的愿望不是打印相关图上的每个文本标签。

M <- cor(mtcars)
corrplot(M, diag = FALSE, method = "ellipse", type = "upper", tl.col = "black")

在此处输入图像描述

有没有办法不打印图中的每个文本标签?我想打印所有其他标签。

或者,为了阅读情节,我想使用变量组作为唯一的文本标签。从聚类中,我发现数据中可能有 3 个组。

#Reorder data collected in mtcars in this way: 
mtcars2 <- mtcars[ , c("carb", "wt", "hp", "cyl", "disp", 
            "qsec", "vs",
            "mpg", "drat", "am", "gear")
            ]
#Let's say I have the following groups corresponding to these variables
groups <- c(rep("Engine", 5), rep("Speed", 2), rep("Fuel", 4) )
R <- cor(mtcars2)
colnames(R) <- groups 

我想在 corrogram 的顶部唯一地打印这些组名。现在,它们为每个变量打印。再说一次,我可以只为一组变量打印一次组名(“Engine”、“Speed”、“Fuel”)吗?

corrplot(R, diag = FALSE, method = "ellipse", type = "upper", tl.col = "black")

实际上,我正在使用的相关图看起来像这样。

set.seed(234)
A <- matrix(rnorm(1e+05), ncol = 100, dimnames = list(NULL, paste0("VeryLongName", 1:100)))
corrplot(cor(A), diag = FALSE, method = "ellipse", type = "upper")

该选项tl.cex = 0.5确实有效,但我更喜欢使用更大更少的标签。

总之,我想调整corrplot()为(1)打印每隔一个标签或(2)在轴上唯一地打印组。

这项工作是使用 corrplot 0.84 版完成的。

标签: rr-corrplot

解决方案


也许包括空字符串groups

require(corrplot)
#Reorder data collected in mtcars in this way: 
mtcars2 <- mtcars[ , c("carb", "wt", "hp", "cyl", "disp", 
                       "qsec", "vs",
                       "mpg", "drat", "am", "gear")
                   ]
#Let's say I have the following groups corresponding to these variables
groups <- c("","Engine",rep("", 3), "Speed","", "Fuel",rep("", 3) )
rows <- c("Engine","",rep("", 3), "Speed","", "Fuel",rep("", 3) )

R <- cor(mtcars2)
colnames(R) <- groups 
rownames(R) <- rows
corrplot(R, diag = FALSE, method = "ellipse", type = "upper", tl.col = "black")

在此处输入图像描述


推荐阅读