[英]How to increase the size of the name of variables in PerformanceAnalytics::chart.Correlation and break line?
I want to increase the font size of variable names in the diagonal (and break lines too, if possible).我想增加对角线中变量名称的字体大小(如果可能的话,也要增加断线)。 How can I do that?
我怎样才能做到这一点? My try:
我的尝试:
df <- structure(list(Coop. = c(3.75, 5, 4.75, 4, 5, 4.5, 4.75, 5, 4,
5), `Papel Imp.` = c(3.6, 5, 4.6, 4.4, 5, 4.6, 4, 4.8, 4.6, 5
), `Esf./Melh.` = c(4.25, 5, 5, 3.625, 4.875, 4.125, 3.5, 4.5,
4.75, 5), `Pun. Erros` = c(2.16666666666667, 3, 3.66666666666667,
4.33333333333333, 2.66666666666667, 3.66666666666667, 3.33333333333333,
3.16666666666667, 4, 2.16666666666667), `Recon. Desig.` = c(2.42857142857143,
1.14285714285714, 1, 3.71428571428571, 1.42857142857143, 2.85714285714286,
2.57142857142857, 1.42857142857143, 4, 1.14285714285714), `Riv. Membr.` = c(2.33333333333333,
2.66666666666667, 5, 3.33333333333333, 3, 2.33333333333333, 4,
3.33333333333333, 2.66666666666667, 2.66666666666667), `Média PREPARAÇÃO` = c(5.75555555555556,
5.83333333333333, 6.65555555555556, 4.62222222222222, 6.31111111111111,
5.7, 5.25555555555556, 6.65555555555556, 5.84444444444444, 6.83333333333333
), `Média EXECUÇÃO` = c(5.15, 6.16666666666667, 5.88333333333333,
4.8, 6.93333333333333, 6.43333333333333, 5.58333333333333, 6.11666666666667,
6.08333333333333, 6.43333333333333), `Média AVALIAÇÃO` = c(5.45833333333333,
6.54166666666667, 6.625, 5.91666666666667, 5.45833333333333,
6.25, 5.66666666666667, 6.625, 6.25, 6.75), `Média AJUSTES` = c(4.9,
6.225, 6.95, 4.325, 6.7625, 6.4, 5.85, 6.125, 4.875, 6.5), `Média GME` = c(5.7,
6.65, 6.75, 5.15, 6.875, 6.55, 5.925, 6.7, 5.225, 6.775), `Treinamento Instrução (TI)` = c(5.66666666666667,
5, 7, 2, 7, 6.33333333333333, 4.66666666666667, 7, 6.66666666666667,
7), `Tratamento Pessoal (TP)` = c(5.8, 7, 6.8, 2, 6.4, 5, 5.2,
6.6, 5, 6.8), `Desempenho da Equipe` = c(3, 5, 5, 3.66666666666667,
7, 5.66666666666667, 6, 6, 4.33333333333333, 6.33333333333333
), `Desempenho Individual` = c(5.33333333333333, 6.66666666666667,
5.33333333333333, 5.33333333333333, 6.33333333333333, 5.66666666666667,
5.33333333333333, 6.33333333333333, 5.66666666666667, 7)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
My code:我的代码:
PerformanceAnalytics::chart.Correlation(df, method = "pearson", hist = F)
I know that this graph is based on pairs(), but the solution in this question didn't work for me.我知道这个图基于pairs(),但是这个问题中的解决方案对我不起作用。
Well, it doesn't work because that function is bugged.好吧,它不起作用,因为该功能被窃听了。 The arguments in
...
are not passed through pairs
. ...
中的参数不通过pairs
传递。
So just rewrite your own function this way:因此,只需以这种方式重写您自己的函数:
mychart.Correlation <- function (R, method = c("pearson", "kendall", "spearman"), ...){
x = PerformanceAnalytics::checkData(R, method = "matrix")
if (missing(method)) method = method[1]
cormeth <- method
panel.cor <- function(x, y, digits = 2, prefix = "",
use = "pairwise.complete.obs",
method = cormeth,
cex.cor, ...) {
usr <- par("usr")
on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- cor(x, y, use = use, method = method)
txt <- format(c(r, 0.123456789), digits = digits)[1]
txt <- paste(prefix, txt, sep = "")
if (missing(cex.cor)) cex <- 0.8/strwidth(txt)
test <- cor.test(as.numeric(x), as.numeric(y), method = method)
Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " "))
text(0.5, 0.5, txt, cex = cex * (abs(r) + 0.3)/1.3)
text(0.8, 0.8, Signif, cex = cex, col = 2)
}
pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, ...)
}
names(df) <- gsub(" ", "\n", names(df))
mychart.Correlation(df, method = "pearson", cex.labels = 1.5)
You can see that in the GitHub version of the package this issue has already been solved ( ...
are correctly present in pairs
), while in the CRAN version there are no ...
你可以看到在GitHub 版本的包中这个问题已经解决了(
...
正确地pairs
存在),而在CRAN 版本中没有...
So another way to solve your problem is to install the GitHub version of the package in this way:所以解决你的问题的另一种方法是通过这种方式安装 GitHub 版本的包:
devtools::install_github("braverock/PerformanceAnalytics")
names(df) <- gsub(" ", "\n", names(df))
PerformanceAnalytics::chart.Correlation(df, method = "pearson", hist = F, cex.labels=1.5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.