I would like to have horizontal and vertical labels on x-axis and y-axis, see the following pseudocode. Henrik's comment of the related thread 2013 is about turning off diagonal labels and then trying to associate labels for the axes, but I do not want to turn off the diagonal labels
You may turn the diagonal labels off by setting labels = NULL. Then you can try to add your labels where you wish by using text
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)
Fig. 1 test data
Testing JayT's proposal
It would be nice to overload the first parameter place with all possible parameters and then have only one extra paremeter ids
in the new function; pseudocode
# 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)
}
Attempt to use it but the following error
corrgramLabels(M,
upper.panel=panel.pie,
lower.panel=panel.shade,
text.panel=panel.txt,
order=NULL,
diag.panel=panel.minmax,
main=title)
Error
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
Proposal for the solution
I actually think that the best solution would be a function independent of corrgram
. Start a function createLabels()
after corrgram()
and you get the result. Is that possible?
OS: Debian 8.5
R: 3.3.1
Related: Corrgram Package Horizontal and Vertical Labels