【发布时间】:2016-11-03 22:21:38
【问题描述】:
我想在 x 轴和 y 轴上有水平和垂直标签,请参阅以下伪代码。 Henrik 对相关线程 2013 的评论是关于关闭对角线标签,然后尝试关联轴的标签,但我不想关闭对角线标签
您可以通过设置标签 = NULL 来关闭对角线标签。然后您可以尝试使用文本在您希望的位置添加标签
library("corrgram")
ids <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
# https://cran.r-project.org/web/packages/corrgram/vignettes/corrgram_examples.html
corrgram(baseball,main="Baseball data PC2/PC1 order") +
xlab("Patient 1 ID") +
ylab("Patient 2 ID") +
scale_x_discrete(labels = ids) +
scale_y_discrete(labels = ids)
图。 1个测试数据
测试 JayT 的提案
最好用所有可能的参数重载第一个参数位置,然后在新函数中只有一个额外的参数ids;伪代码
# https://stackoverflow.com/a/40387233/54964
corrgramLabels <- function(x, ids){
corrgram(x=x)
mtext("Patient 1 ID", side = 1, line = 4)
mtext("Patient 2 ID", side = 2, line = 3)
x_at <- seq(0.075, 0.925, length.out = length(ids))
y_at <- seq(0.075, 0.91, length.out = length(ids))
axis(1, at=x_at, labels=x_labels, line = 1.5, tick=F, cex.axis=.7)
axis(2, at=y_at, labels=y_labels, line = 1, tick=F, cex.axis=.7)
}
尝试使用但出现以下错误
corrgramLabels(M,
upper.panel=panel.pie,
lower.panel=panel.shade,
text.panel=panel.txt,
order=NULL,
diag.panel=panel.minmax,
main=title)
错误
Error in corrgramLabels(M, upper.panel = panel.pie, lower.panel = panel.shade, :
unused arguments (upper.panel = panel.pie, lower.panel = panel.shade, text.panel = panel.txt, order = NULL, diag.panel = panel.minmax, main = title)
Execution halted
解决方案建议
我实际上认为最好的解决方案是独立于corrgram 的函数。在corrgram() 之后启动一个函数createLabels(),你就会得到结果。这可能吗?
操作系统:Debian 8.5
R:3.3.1
相关:Corrgram Package Horizontal and Vertical Labels
【问题讨论】: