R-更改Corrplot的轴标签的大小 [英] R - change size of axis labels for corrplot

查看:267
本文介绍了R-更改Corrplot的轴标签的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在corrplo t上使用以下内容:

I am using the following with corrplot:

require("corrplot") ## needs the corrplot package
corrplot(cor(lpp_axis1, lpp_axis2), method=c("number"), bg = "grey10",
         addgrid.col = "gray50", tl.offset = 2, tl.cex=2,
         tl.col = "black", 
         col = colorRampPalette(c("yellow","green","navyblue"))(100))

这是使用此处可用的csv文件创建的.

This is created with a csv file available here.

该图很好,我可以根据需要调整cl标签.我试过调整x和y轴上的标签,而没有任何影响.我看着不断变化的mar-但是我还没有找到办法.我无法尝试使用cex.label更改大小.

The graph is fine and I can adjust the cl labels all I want. I've tried adjusting the labels on x and y axis with no impact. I looked at changing mar - yet I haven't found a way to. I was unsuccessful with trying to use cex.label to change size.

问题-如何使Corrplot(不是cl,不在网格中)显示的文本变大?

The question - how can I make the text appearing for corrplot (not the cl, and not in the grid) larger?

两个轴是以下数据帧:

lpp_axis1 <- data.frame("Compile Source Code" = Q3A.1, "View Source Code" = Q3A.2, "Change Source Code" = Q3A.3, "Write Documentation" = Q3A.8, "File Bug Reports"= Q3B.3, "Ask Questions" = Q3B.5, "Provide Answers" = Q3B.6, "Overall Participation" = Q3a3bConsolidated)

lpp_axis2 <- data.frame("Identification" = Q1,"Overall Learning" = Q6Consolidated,  "Learning Programming" = Q6.1,  "Learning about Computers" = Q6.2, "Learning Teamwork" =  Q6.3)

输出

str(lpp_axis1)

> str(lpp_axis1)
'data.frame':   4603 obs. of  8 variables:
 $ Compile.Source.Code  : int  4 2 3 2 2 2 3 2 2 0 ...
 $ View.Source.Code     : int  4 2 1 1 2 2 3 1 1 0 ...
 $ Change.Source.Code   : int  4 1 0 1 2 1 2 1 1 0 ...
 $ Write.Documentation  : int  4 1 2 2 3 0 3 0 1 0 ...
 $ File.Bug.Reports     : int  4 4 1 2 2 0 2 0 0 0 ...
 $ Ask.Questions        : int  4 4 2 4 2 1 2 1 3 0 ...
 $ Provide.Answers      : int  2 4 1 4 4 0 3 1 3 0 ...
 $ Overall.Participation: int  49 26 14 32 31 8 27 10 15 0 ...

来自

packageDescription("corrplot")

表示:

Package: corrplot
Type: Package
Title: visualization of a correlation matrix
Version: 0.30
Date: 2010-05-30
Author: Taiyun Wei
Suggests: seriation, cairoDevice, Cairo,
Maintainer: Taiyun Wei <weitaiyun@gmail.com>
Description: The corrplot package is a graphical display of a
        correlation matrix, confidence interval. It also contains some
        algorithms to do matrix reordering.
License: GPL-2 | GPL-3
LazyLoad: yes
URL: http://corrplot.r-forge.r-project.org
Repository: CRAN
Repository/R-Forge/Project: corrplot
Repository/R-Forge/Revision: 45
Date/Publication: 2010-05-31 07:44:14
Packaged: 2010-05-30 20:39:16 UTC; rforge
Built: R 2.11.1; ; 2011-03-19 00:22:49 UTC; unix

-- File: /home/user/R/x86_64-pc-linux-gnu-library/2.11/corrplot/Meta/package.rds 
> 

corrplot维护人员写回了一个替代的corrplot.r.此处

The corrplot maintainer wrote back with an alternate corrplot.r available here

使用此Corrplot和下面的示例代码,文本大小是可以接受的.但是,尝试增加它也会产生相同的效果.

Using the this corrplot and the example code below, the text size is acceptable. However, attempts to increase it also produce the same effects.

source("http://misterdavis.org/R_info/corrplot.r")
corrplot(cor(lpp_axis1, lpp_axis2), addn=T,
         addgrid.col = "gray50", tl.cex=2, assign.col="min2max",
         tl.col = "black", cl.ratio=0.4, addcolor="no",
         col = colorRampPalette(c("yellow","green","blue"))(100))

使用此处可用的相关圈子的较早版本可以根据自己的意愿调整文字. (尽管该图缺少后来的更完善的corrplot程序包的某些功能.)cex可用于cex.在时间允许的情况下,我可能会尝试调整两者以提出一种令人满意的方法.

Using an earlier version of the correlation circles available here, it is possible to adjust the text to one's heart desire. (Though the graph lacks some of the functionality of the later, more refined corrplot package.) cex can be used for cex. I may try to tweak the two to come up with a happy medium as time permits.

使用较旧的相关圆脚本,以下代码将产生足够大的X和Y轴标签:

Using the older correlation circles script, the following code produces sufficiently large X and Y axis labels:

circle.corr(cor(lpp_axis1, lpp_axis2), bg = "gray50",   col = colorRampPalette(c("navyblue","white", "red"))(100), cex=1.5)

推荐答案

Update2

实际上,由于提供了代码和数据,因此现在是一个真正可复制的示例:

Actually a real reproducible example is now, thanks to code and data being provided:

d1 <- read.csv(url("http://misterdavis.org/r_wiki/r_results_1231_2010"))
lpp_axis1 <- with(d1, data.frame("Compile Source Code" = Q3A.1,
                                 "View Source Code" = Q3A.2,
                                 "Change Source Code" = Q3A.3, 
                                 "Write Documentation" = Q3A.8, 
                                 "File Bug Reports"= Q3B.3,
                                 "Ask Questions" = Q3B.5,
                                 "Provide Answers" = Q3B.6,
                                 "Overall Participation" = Q3a3bConsolidated))

lpp_axis2 <- with(d1, data.frame("Identification" = Q1,
                                 "Overall Learning" = Q6Consolidated,  
                                 "Learning Programming" = Q6.1,
                                 "Learning about Computers" = Q6.2, 
                                 "Learning Teamwork" =  Q6.3))

corrplot(cor(lpp_axis1, lpp_axis2), method=c("number"), bg = "grey10",
         addgrid.col = "gray50", tl.cex=1,
         tl.col = "black", 
         col = colorRampPalette(c("yellow","green","navyblue"))(100))
dev.new()
corrplot(cor(lpp_axis1, lpp_axis2), method=c("number"), bg = "grey10",
         addgrid.col = "gray50", tl.cex=2,
         tl.col = "black", 
         col = colorRampPalette(c("yellow","green","navyblue"))(100))

通过dev.new(),您可以一次在屏幕上进行比较,而无需将绘图区域分为两个面板.

The dev.new() allows you to have both on screen at once to compare, without splitting the plotting region into two panels.

tl.offset似乎引起了更多的问题,因此,我将其遗漏了.我包括以下两个数字:

The tl.offset seems to cause more problems than it is worth, so I have left it out. I include the two figures below:

使用tl.cex = 1

的Corrplot

使用tl.cex = 2

的Corrplot

如您所见,我无法重现您所看到的问题; tl.cex仅更改轴标签的大小.请注意,这是不使用tl.offset的,但是其余的绘图代码与您的相同.

As you can see, I can't reproduce the problem you are seeing; tl.cex is only changing the size of the size of the axis labels. Note this is without using tl.offset but the rest of the plotting code is the same as yours.

这是我从packageDescription()那里得到的:

R> packageDescription("corrplot")
Package: corrplot
Type: Package
Title: visualization of a correlation matrix
Version: 0.30
Date: 2010-05-30
Author: Taiyun Wei
Suggests: seriation, cairoDevice, Cairo,
Maintainer: Taiyun Wei <weitaiyun@gmail.com>
Description: The corrplot package is a graphical display of a
        correlation matrix, confidence interval. It also contains some
        algorithms to do matrix reordering.
License: GPL-2 | GPL-3
LazyLoad: yes
URL: http://corrplot.r-forge.r-project.org
Repository: CRAN
Repository/R-Forge/Project: corrplot
Repository/R-Forge/Revision: 45
Date/Publication: 2010-05-31 07:44:14
Packaged: 2010-05-30 20:39:16 UTC; rforge
Built: R 2.13.0; ; 2011-04-01 12:33:21 UTC; unix

-文件:/home/gavin/R/libs/corrplot/Meta/package.rds

-- File: /home/gavin/R/libs/corrplot/Meta/package.rds

将其与您系统上的一个进行比较,并尝试上面的示例,以便我们运行完全相同的代码进行比较.

Compare it with the one on your system and try the example above so we are running exactly the same code for comparison.

原始示例 这是一个可重现的示例:

Original Example Here is a reproducible example:

require(corrplot)
data(mtcars)
corr <- cor(mtcars)
corrplot(corr, method = "number", tl.cex = 2)

更新

好的,我现在看到了问题.使用tl.offset,可以将标签从相关图形进一步推到边缘.这似乎是corrplot()中遗忘问题的错误,好像您没有设置tl.offset一样,它缩放了相关图形以适应标签.我能看到的唯一解决方案是根本不设置tl.offset或将其设置为较小的值.这是一个极端的示例:

Ok, I see the problem now. With tl.offset, you push the labels away from the correlation graphic further out into the margins. This seems either a bug on infelicity in corrplot() as if you don't set tl.offset it scales the correlation graphic to accommodate the labels. The only solution I can see is to not set tl.offset at all, or set it to a smaller value Here is an extreme example:

layout(matrix(1:2, ncol = 2))
corrplot(corr, method = "number", tl.cex = 2, tl.offset = 3)
corrplot(corr, method = "number", tl.cex = 2)
layout(1)

可以通过更改绘图设备的相对尺寸来进行改进-如果在屏幕上,请增加绘图设备窗口的宽度或高度(或两者)直到所有标签都可见.如果这是另一台设备(例如pdf()png()),则在创建设备时需要更改其尺寸.

You can improve things, by altering the relative dimensions of the plot device - if on screen, increase the width or height (or both) of the plot device window until all the labels are visible. If this is another device (pdf() or png() say), then you'll need to alter the dimensions of the device when you create it.

原始(可重现的示例)给出的内容:

Original Which [The reproducible example] gives:

您不清楚x和y轴标签有什么问题,但是corrplot()会更改打印边距以容纳标签.您已经通过设置参数tl.cex = 2声明了这些x和y轴标签的相对大小.如果您希望标签更大,请增加此值:

You aren't clear what the problem with the x and y axis labels, but corrplot() alters the plot margins to accommodate the labels. You have already stated the relative size of these x and y axis labels by setting argument tl.cex = 2. If you want the labels bigger, increase this value:

corrplot(corr, method = "number", tl.cex = 4)

,如果需要较小的标签,请将tl.cex设置为较小的值:

and if you want smaller labels, set tl.cex to a smaller value:

corrplot(corr, method = "number", tl.cex = 0.8)

鉴于这些是情节上唯一的x y标签,这有帮助吗?如果没有,哪些标签需要更改?

Given these are the only x and y labels on the plot, does this help? If not, which labels need altering?

这篇关于R-更改Corrplot的轴标签的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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