如何在Corrplot中更改配色方案 [英] How to change color scheme in corrplot

查看:1799
本文介绍了如何在Corrplot中更改配色方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中使用corrplot来可视化相关系数矩阵,如下所示.

I am using corrplot in R to visualise a correlation-coefficient matrix as follows.

library(corrplot) 
library(datasets)
corrplot(abs(cor(mtcars)), method="color", tl.pos="n", cl.lim = c(0,1))

默认配色方案基于 蓝色 .但是,我想将其更改为基于 red 的.我知道我需要使用colorRampPalette指定所需的颜色.但是,我不知道要使用什么颜色代码.有人可以帮我吗?

The default colour scheme is blue-based. However, I would like to change it to red-based. I know I need to use colorRampPalette to specify colours I want. However, I could not figure out what colour codes to use. Could anyone help me with this, please?

谢谢!

推荐答案

如果您要使用红色,则可以像已经提到的那样定义自己的colorRampPalette.请注意,该图似乎将颜色范围设置为-1到1(即使您调整cl.lim值).因此,您仍然需要为渐变中的-1到0范围定义颜色.例如

If you want to use red, you can define your own colorRampPalette as you've alread mentioned. Just note that the plot seems to set the range of colors from -1 to 1 (even if you adjust the cl.lim value). Thus you still need to define colors for the -1 to 0 range in your ramp. For example

corrplot(abs(cor(mtcars)), method="color", tl.pos="n", 
    cl.lim=c(0,1), col=colorRampPalette(c("blue","white","red"))(200))

会产生

即使我们在调色板中定义了蓝色",它也不会显示,因为我们将颜色条的值限制为大于1.

and even though we defined "blue" in the color palette, it doesn't show up because we limited the color bar to values greater than 1.

如果您将cl.lim

corrplot(abs(cor(mtcars)), method="color", tl.pos="n")

这篇关于如何在Corrplot中更改配色方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆