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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:03:19+00:00 2026-06-14T01:03:19+00:00

I asked a question HERE about grid arrange and got a terrific response. I

  • 0

I asked a question HERE about grid arrange and got a terrific response. I want to reduce the space between plots now but get an error. First I present the code that works and then the error code (what I tried). I can’t actually find grid.arrange and have always assumed it comes from gridExtra but I may be incorrect.

so 2 parts:

  1. How can I reduce space between plots with grid arrange
  2. Where can I find documentation about grid.arrange (Baptiste I know you maintain gridExtra so please correct my thinking or use of the package if I’m not using it in the way it was intended.)

Good code bad space

require(ggplot2);require(gridExtra)
A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +
    coord_flip() + ylab("")
B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() 


 gA <- ggplot_gtable(ggplot_build(A))
 gB <- ggplot_gtable(ggplot_build(B))
 maxWidth = grid::unit.pmax(gA$widths[2:3], gB$widths[2:3])
 gA$widths[2:3] <- as.list(maxWidth)
 gB$widths[2:3] <- as.list(maxWidth)
 grid.arrange(gA, gB, ncol=1)

Bad code (my try)

require(ggplot2);require(gridExtra)
A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +
    coord_flip() + ylab("") + theme(plot.margin= unit(1, "cm"))
B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() 


 gA <- ggplot_gtable(ggplot_build(A))
 gB <- ggplot_gtable(ggplot_build(B))
 maxWidth = grid::unit.pmax(gA$widths[2:3], gB$widths[2:3])
 gA$widths[2:3] <- as.list(maxWidth)
 gB$widths[2:3] <- as.list(maxWidth)
 grid.arrange(gA, gB, ncol=1)

The error:

Error in `[.unit`(theme$plot.margin, 2) : 
  Index out of bounds (unit subsetting)
  • 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-14T01:03:20+00:00Added an answer on June 14, 2026 at 1:03 am

    I was misunderstanding ggplot:

    require(ggplot2);require(gridExtra)
    A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +
        coord_flip() + ylab("") + theme(plot.margin= unit(c(1, 1, -1, 1), "lines"))
    B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() + 
        theme(plot.margin= unit(rep(.5, 4), "lines"))
    
    
     gA <- ggplot_gtable(ggplot_build(A))
     gB <- ggplot_gtable(ggplot_build(B))
     maxWidth = grid::unit.pmax(gA$widths[2:3], gB$widths[2:3])
     gA$widths[2:3] <- as.list(maxWidth)
     gB$widths[2:3] <- as.list(maxWidth)
     grid.arrange(gA, gB, ncol=1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have asked a question about manytomanyfield here which i solved but now a
I asked the original question here , and got a practical response with mixed
I asked a question here about an Linq error that results from mixing Linq-To-SQL
I asked a question here : When To Use IEquatable And Why about using
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked the question here and now i would like to reverse this procedure
A while back, I asked a question on here about how to run an
I've asked here a question about Task Killers and widgets stop working ( SO
i've asked the first question about selects here , i thought, that when i
I have asked this question here about a Python command that fetches a URL

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.