简体   繁体   English

如何在图形中放置colorlegend(corrplot)

[英]how to place colorlegend (corrplot) in graphic

I am using corrplot to create a correlation heatmap, but I don't like the default legend - it is too big. 我使用corrplot来创建相关热图,但我不喜欢默认的图例 - 它太大了。 So I was trying to use the colorlegend() to add the legend after I create the plot (and disable the default legend with cl.pos="n" ). 所以我在创建绘图后尝试使用colorlegend()添加图例(并使用cl.pos="n"禁用默认图例)。

Only problem is that I can't figure out how to change the position of the legend - it ends up on the lower left. 唯一的问题是我无法弄清楚如何改变图例的位置 - 它最终在左下角。 Ideally, I could place it on the top right, but I looked through the options for colorlegend and plot and can't figure this out. 理想情况下,我可以将它放在右上角,但我查看了colorlegend和plot的选项,但无法弄清楚这一点。

For example: 例如:

# load libraries and create color scale
library(corrplot)
library(RColorBrewer)
scalebluered <- colorRampPalette(brewer.pal(8, "RdBu"))(8)

# get data into correlation matrix
data(mtcars)
cars.matrix <- as.matrix(mtcars[c(2:8)])
cars.corr <- cor(cars.matrix)

# plot it
corrplot(cars.corr, method="shade", shade.col=NA, tl.col="black", 
         tl.srt=45, addgrid.col="black", type="lower", diag=FALSE, cl.pos="n")

# add legend
colorlegend(scalebluered, c(seq(-1,1,.25)), align="l", vertical=TRUE, addlabels=TRUE)

output: http://i42.tinypic.com/14wsqc0.png 输出: http//i42.tinypic.com/14wsqc0.png

几个月后,我重新审视并弄清楚..只需添加xlim和ylim来定义图例的尺寸..超级简单!

colorlegend(xlim=c(10,15), ylim=c(10,15), scalebluered, c(seq(-1,1,.25)), align="l", vertical=TRUE, addlabels=TRUE)

like this? 像这样? changing cl.pos="n" to "r" cl.pos="n" to "r"

corrplot(cars.corr, method="shade", shade.col=NA, tl.col="black", 
         tl.srt=45, addgrid.col="black", type="lower", diag=FALSE, cl.pos="r")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM