如何在图形中放置colorlegend(corrplot) [英] how to place colorlegend (corrplot) in graphic
问题描述
我正在使用corrplot
创建关联热图,但是我不喜欢默认图例-它太大.因此,在创建绘图后,我试图使用colorlegend()
添加图例(并使用cl.pos="n"
禁用默认图例).
I am using corrplot
to create a correlation heatmap, but I don't like the default legend - it is too big. 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
的选项并进行了绘制,因此无法弄清楚.
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.
例如:
# 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)
输出: http://i42.tinypic.com/14wsqc0.png >
推荐答案
几个月后,我再次进行了讨论并弄清楚了..只需添加xlim和ylim即可定义图例的尺寸.
Months later, I revisit this and figure it out.. just add xlim and ylim to define the dimensions of the legend.. super easy!
colorlegend(xlim=c(10,15), ylim=c(10,15), scalebluered, c(seq(-1,1,.25)), align="l", vertical=TRUE, addlabels=TRUE)
这篇关于如何在图形中放置colorlegend(corrplot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!