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 7728221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:39:50+00:00 2026-06-01T05:39:50+00:00

I would like to center a title with respect to a plot matrix (and

  • 0

I would like to center a title with respect to a plot matrix (and not the overall plot) I created with this code:

d <- 3
d2 <- d*d
layout.mat <- matrix(1:d2, byrow=TRUE, ncol=d) # plot matrix
layout.mat <- cbind(layout.mat, rep(0, d)) # space
layout.mat <- cbind(layout.mat, rep(d2+1, d)) # column on the right side
wspace <- 6*par("csi")*2.54 # width of the space in character height in cm
wside <- 3*par("csi")*2.54 # width of the right side in character height in cm
layout(layout.mat, respect=TRUE, widths=c(rep(1, d), lcm(wspace), lcm(wside)))
layout.show(d2+1)
par(mar=rep(0, 4), oma=c(4,4,6,4))
for(i in 1:d){
    for(j in 1:d){
        plot.new()
        plot.window(xlim=c(0,1), ylim=c(0,1))
        ll <- par("usr")
        rect(ll[1], ll[3], ll[2], ll[4])
        text(0.5, 0.5, paste("i=",i,", j=",j,sep=""), cex=1.4)
    }
}
plot.new()
plot.window(xlim=c(0,1), ylim=c(0,1))
ll <- par("usr")
rect(ll[1], ll[3], ll[2], ll[4])
text(0.5, 0.5, "side", cex=1.4)

## title
mtext("This title should be centered according to the plot matrix", side=3,
      line=2, outer=TRUE, adj=0.5, at=0.5)

How can I determine (with given fixed distances wspace and wside) the width of plot region so that I can subtract wspace+wside from it to determine the width of the plot matrix? The ultimate goal is to determine a precise value for adj of mtext such that the title is centered above the plot matrix and not the overall plotting region.

  • 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-06-01T05:39:51+00:00Added an answer on June 1, 2026 at 5:39 am

    How about adding this code inside your for loop:

    if (i == 1 & j == 2){
       mtext("This title should be centered according to the plot matrix", side=3,
            line=2, outer=FALSE, adj=0.5, at=0.5)
    }
    

    Note the change to outer = FALSE. Here’s what it looks like, with shorter title text (the long version runs off either side in a small plot, but is still centered):

    enter image description here

    Of course, this hack only works if you have an odd number of columns. A more general solution may be to alter the layout to include a short, wide horizontal region at the top, and plot text in that region directly:

    d <- 4
    d2 <- d*d
    layout.mat <- matrix(1:d2, byrow=TRUE, ncol=d) # plot matrix
    layout.mat <- cbind(layout.mat, rep(0, d)) # space
    layout.mat <- cbind(layout.mat, rep(d2+1, d)) # column on the right side
    layout.mat <- rbind(c(rep(18,d),0,0),layout.mat) #Add row on top
    wspace <- 6*par("csi")*2.54 # width of the space in character height in cm
    wside <- 3*par("csi")*2.54 # width of the right side in character height in cm
    #Note adjustments to heights
    layout(layout.mat, respect=TRUE, widths=c(rep(1, d), lcm(wspace), lcm(wside)),
           heights = c(0.25,rep(1,nrow(layout.mat)-1)))
    layout.show(d2+1)
    par(mar=rep(0, 4), oma=c(4,4,6,4))
    for(i in 1:d){
        for(j in 1:d){
            plot.new()
            plot.window(xlim=c(0,1), ylim=c(0,1))
            ll <- par("usr")
            rect(ll[1], ll[3], ll[2], ll[4])
            text(0.5, 0.5, paste("i=",i,", j=",j,sep=""), cex=1.4)
        }
    }
    plot.new()
    plot.window(xlim=c(0,1), ylim=c(0,1))
    ll <- par("usr")
    rect(ll[1], ll[3], ll[2], ll[4])
    text(0.5, 0.5, "side", cex=1.4)
    
    ## title
    plot.new()
    plot.window(xlim=c(0,1), ylim=c(0,1))
    ll <- par("usr")
    #rect(ll[1], ll[3], ll[2], ll[4])
    text(0.5, 0.5, "top", cex=1.4)
    

    enter image description here

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

Sidebar

Related Questions

I would like to center a text element (in this case, the h2 sub-headline)
What I want to do is, make layout like this: Title Date Long text
I would like to place a title in the center of a pie/donut chart
I have an aspx Login control and I would like to center it on
I would like to Show my Messagebox in the center of its parent form.
I've made a menu strip that I would like fixed to the bottom center
I have written a plugin for Windows 7 Media Center, and I would like
I would like to center the titlebar text on a jqGrid without messing up
I am using a custom title view and would like to show/hide a progressbar
I would like to create a modal window which will only mask the center

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.