Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:30:08+00:00 2026-05-31T09:30:08+00:00

By default, pairs() puts the axes on all sides of the plot, alternating between

  • 0

By default, pairs() puts the axes on all sides of the plot, alternating between the sides. However, I’m putting the correlation between the data sets in the upper triangle, so I want to adjust the axis position like this:

this is how it should look like

Which parameters do I need to set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:30:09+00:00Added an answer on May 31, 2026 at 9:30 am

    You could custumize the pairs function.
    If you look at the code, the axis are drawn within 2 nested for-loops (one for rows and one for colums):

    Here is a custimized pairs function, were I just edited the sides in localAxis() within these for-loops:

    pairs2 <- 
      function (x, labels, panel = points, ..., lower.panel = panel, 
                upper.panel = panel, diag.panel = NULL, text.panel = textPanel, 
                label.pos = 0.5 + has.diag/3, cex.labels = NULL, font.labels = 1, 
                row1attop = TRUE, gap = 1) 
      {
        textPanel <- function(x = 0.5, y = 0.5, txt, cex, font) text(x, 
                                                                     y, txt, cex = cex, font = font)
        localAxis <- function(side, x, y, xpd, bg, col = NULL, main, 
                              oma, ...) {
          if (side%%2 == 1) 
            Axis(x, side = side, xpd = NA, ...)
          else Axis(y, side = side, xpd = NA, ...)
        }
        localPlot <- function(..., main, oma, font.main, cex.main) plot(...)
        localLowerPanel <- function(..., main, oma, font.main, cex.main) lower.panel(...)
        localUpperPanel <- function(..., main, oma, font.main, cex.main) upper.panel(...)
        localDiagPanel <- function(..., main, oma, font.main, cex.main) diag.panel(...)
        dots <- list(...)
        nmdots <- names(dots)
        if (!is.matrix(x)) {
          x <- as.data.frame(x)
          for (i in seq_along(names(x))) {
            if (is.factor(x[[i]]) || is.logical(x[[i]])) 
              x[[i]] <- as.numeric(x[[i]])
            if (!is.numeric(unclass(x[[i]]))) 
              stop("non-numeric argument to 'pairs'")
          }
        }
        else if (!is.numeric(x)) 
          stop("non-numeric argument to 'pairs'")
        panel <- match.fun(panel)
        if ((has.lower <- !is.null(lower.panel)) && !missing(lower.panel)) 
          lower.panel <- match.fun(lower.panel)
        if ((has.upper <- !is.null(upper.panel)) && !missing(upper.panel)) 
          upper.panel <- match.fun(upper.panel)
        if ((has.diag <- !is.null(diag.panel)) && !missing(diag.panel)) 
          diag.panel <- match.fun(diag.panel)
        if (row1attop) {
          tmp <- lower.panel
          lower.panel <- upper.panel
          upper.panel <- tmp
          tmp <- has.lower
          has.lower <- has.upper
          has.upper <- tmp
        }
        nc <- ncol(x)
        if (nc < 2) 
          stop("only one column in the argument to 'pairs'")
        has.labs <- TRUE
        if (missing(labels)) {
          labels <- colnames(x)
          if (is.null(labels)) 
            labels <- paste("var", 1L:nc)
        }
        else if (is.null(labels)) 
          has.labs <- FALSE
        oma <- if ("oma" %in% nmdots) 
          dots$oma
        else NULL
        main <- if ("main" %in% nmdots) 
          dots$main
        else NULL
        if (is.null(oma)) {
          oma <- c(4, 4, 4, 4)
          if (!is.null(main)) 
            oma[3L] <- 6
        }
        opar <- par(mfrow = c(nc, nc), mar = rep.int(gap/2, 4), oma = oma)
        on.exit(par(opar))
        dev.hold()
        on.exit(dev.flush(), add = TRUE)
        for (i in if (row1attop) 
          1L:nc
             else nc:1L) for (j in 1L:nc) {
               localPlot(x[, j], x[, i], xlab = "", ylab = "", axes = FALSE, 
                         type = "n", ...)
               if (i == j || (i < j && has.lower) || (i > j && has.upper)) {
                 box()
                 # edited here...
                 #           if (i == 1 && (!(j%%2) || !has.upper || !has.lower)) 
                 #           localAxis(1 + 2 * row1attop, x[, j], x[, i], 
                 #                       ...)
                 # draw x-axis
                 if (i == nc & j != nc) 
                   localAxis(1, x[, j], x[, i], 
                             ...)
                 # draw y-axis
                 if (j == 1 & i != 1) 
                   localAxis(2, x[, j], x[, i], ...)
                 #           if (j == nc && (i%%2 || !has.upper || !has.lower)) 
                 #             localAxis(4, x[, j], x[, i], ...)
                 mfg <- par("mfg")
                 if (i == j) {
                   if (has.diag) 
                     localDiagPanel(as.vector(x[, i]), ...)
                   if (has.labs) {
                     par(usr = c(0, 1, 0, 1))
                     if (is.null(cex.labels)) {
                       l.wid <- strwidth(labels, "user")
                       cex.labels <- max(0.8, min(2, 0.9/max(l.wid)))
                     }
                     text.panel(0.5, label.pos, labels[i], cex = cex.labels, 
                                font = font.labels)
                   }
                 }
                 else if (i < j) 
                   localLowerPanel(as.vector(x[, j]), as.vector(x[, 
                                                                  i]), ...)
                 else localUpperPanel(as.vector(x[, j]), as.vector(x[, 
                                                                     i]), ...)
                 if (any(par("mfg") != mfg)) 
                   stop("the 'panel' function made a new plot")
               }
               else par(new = FALSE)
             }
        if (!is.null(main)) {
          font.main <- if ("font.main" %in% nmdots) 
            dots$font.main
          else par("font.main")
          cex.main <- if ("cex.main" %in% nmdots) 
            dots$cex.main
          else par("cex.main")
          mtext(main, 3, 3, TRUE, 0.5, cex = cex.main, font = font.main)
        }
        invisible(NULL)
      }
    data(iris)
    pairs2(iris[1:4], main = "Anderson's Iris Data -- 3 species",pch = 21, bg = c("red", "green3", "blue")[unclass(iris$Species)])
    

    enter image description here

    Edit
    Changed pairs2(), so that the axis appear only on the lower diagonal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ship a default SQLite database, with some predefined key/value pairs in
The default rails XML builder escapes all HTML, so something like: atom_feed do |feed|
I'm using a jqGrid. For add popup for combobox i'm using default data from
as definition: The cartesian product of two sets is the set of all possible
For a small set of key/value pairs (default 2, max 5), a Dictionary<TKey, TValue>
default is 49 how to edit to higher?
The default shell in Mac OS X is bash , which I'm generally happy
By default each row of a Gridview maps to each row in a datatable
By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML
By default the webjump hotlist has the following which I use quite often: M-x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.