简体   繁体   English

如何增加 PerformanceAnalytics::chart.Correlation 和断线中变量名称的大小?

[英]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(),但是这个问题中的解决方案对我不起作用。

Custom Function自定义功能

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)

在此处输入图片说明


Developer Solution开发者解决方案

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.

相关问题 如何更改R中PerformanceAnalytics库中chart.Correlation的颜色? - How to change the colors of chart.Correlation from PerformanceAnalytics library in R? 图表与连续和类别变量的相关性 - chart.Correlation with continious and categorical variables chart.correlation独立与因变量的可视化 - chart.Correlation independent vs dependent variables visualisation 如何从chart.correlation函数中删除有效星 - How to remove significance stars from chart.correlation function 更改图表。相关默认为生成最佳拟合线而不是下三角形中的平滑曲线[R] - change chart.Correlation defaults to produce best fit line rather than smoothed curve in lower triangle [R] 如何使用ggplot2包创建此图表.R中的相关图? - How can I create this chart.Correlation graph in R using the ggplot2 package? 我如何使用 colnames 作为chart.Correlation 的标签,如 corrplot - How do i use colnames as labels for chart.Correlation like in corrplot 更改图表下对角线上的点字符。相关() - Change point characters in lower diagonal of chart.Correlation() 无法更改 R 图中的 pch(点符号)。相关性 - cannot change pch (point symbol) in R chart.Correlation R ggplot2 是否有等效于 Performance Analytics 包中的 chart.Correlation 函数? - R ggplot2 is there are equivalent to the chart.Correlation function in the Performance Analytics package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM