0

I've been trying to adjust the axes of multiple plots using pairs, such that they are all on the same axis. Here's a reproducible example:

structure(list(LS_avg_RT_diff_L1 = c(80.6931818181818, 132.140625, 
17.3957219251338, 17.7260619977038, 132.270508203281, 48.7419786096257, 
61.5816849816849, 44.4324596774193, 80.8417471466198, 65.4357864357864, 
83.2645687645688, 36.264116575592, 67.0728778467909, 60.1642857142856, 
-14.4822346891071, 45.9939516129032, 42.7380090497737, 90.2058823529412, 
27.6024667931689, 93.5517494494738), LS_avg_RT_diff_L2 = c(77.5145135566187, 
40.8939393939395, 29.6952853598016, 72.9280753968254, -14.1512868801005, 
85.6644052464948, 30.2159709618876, -11.433465085639, 64.1141025641025, 
74.4760374050264, 53.6344431687714, 43.5934426229509, -9.48846153846159, 
36.4078947368421, 22.3389830508474, 37.0996168582376, 3.98615617564349, 
101.859614968635, 15.8340548340548, 64.2138275124732), F_Avg_RT_incong_cong_diff = c(171.598614692351, 
102.555176953458, 137.872214816226, 125.230948166877, 51.7965631337389, 
134.295988295988, 120.740762463343, 100.648528099911, 106.099431818182, 
105.072854715378, 70.708551526529, 123.551755014327, 96.0822281167109, 
122.687703999003, 119.429894937918, 120.140225128698, 76.5200041540099, 
111.617893755825, 213.413735177866, 143.796112730807), CS_Avg_RT_sw_stay_diff = c(96.0248439450687, 
13.6687620889749, 43.9708908113163, 106.518604651163, 77.4642017245884, 
31.8150793650793, -54.9493941553814, 43.6563866241286, 11.0111111111111, 
18.3352925809822, 30.7129426129426, 21.9990338164251, -27.7946428571429, 
28.8394863563403, 6.10227272727275, 20.1549806576402, 79.845259391771, 
12.6738336713995, 4.97893772893769, 54.8049335863378)), row.names = c(NA, 
20L), class = "data.frame")

And my code:

panel <- function(x,y){
        points(x,y, col = "blue", pch = 21, bg = "blue")
        abline(lm(y~x), col="red")}

my.text.panel <- function(labels) {
  function(x, y, lbl, ...) {
    if (lbl %in% names(labels)) lbl <- labels[[lbl]]
    text(x, y, lbl, ...)}}

pairs(x = Corr_data_noppt[1:4], 
      xlim = c(-100, 250),
      ylim = c(-100, 250),
      diag.panel = labels,
      text.panel = my.text.panel(c(LS_avg_RT_diff_L1="RT Switching costs for L1", 
                                   LS_avg_RT_diff_L2="RT Switching costs for L2",
                                   F_Avg_RT_incong_cong_diff="Flanker RT costs", 
                                   CS_Avg_RT_sw_stay_diff="Colour-Shape RT costs")),
      lower.panel = panel,
      font.labels = 1, 
      cex.labels = 1.2,
      upper.panel = NULL) #show only the low half of the matrix

According to other cases on here, xlim and ylim can be added as arguments to pairs, but that doesn't work for me and I get an error that they are not taken as such:

Error in upper.panel(...) : 
  unused arguments (xlim = c(-100, 250), ylim = c(-100, 250))

I tried alternatively adding them onto:

panel <- function(x,y){
        points(x,y, col = "blue", pch = 21, bg = "blue")
        abline(lm(y~x), col="red")
        xlim = c(-100, 250)
        ylim = c(-100, 250)}

But that changed absolutely nothing. Any suggestions?

Phil
  • 7,287
  • 3
  • 36
  • 66
Orestes_Fox
  • 189
  • 11

1 Answers1

2

You need to allow additional arguments (e. g. xlim) to your custom panel function by using the dot-dot-dot (...) construct:

panel <- function(x, y, ...){
        points(x,y, col = "blue", pch = 21, bg = "blue")
        abline(lm(y~x), col="red")}
I_O
  • 4,983
  • 2
  • 2
  • 15
  • Or define xlim / ylim: in your function: `panel <- function(x, y){ plot(x, y, col = "blue", pch = 21, bg = "blue", xlim = c(-100, 250), ylim = c(-100, 250)) abline(lm(y~x), col="red") }` – TarJae May 14 '23 at 15:33