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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:46:59+00:00 2026-06-04T08:46:59+00:00

I like to place a table and a plot in the same image. I

  • 0

I like to place a table and a plot in the same image. I am doing this:

my data frame x is this:

1/1/2010 10
1/2/2010 20
1/3/2010 15
1/4/2010 56
1/5/2010 46
1/6/2010 15
1/8/2010 15
1/9/2010 15
1/10/2010 20
1/11/2010 15
1/12/2010 15
1/13/2010 40
1/14/2010 15
1/15/2010 15
1/16/2010 70

p1<-plot(x)
p2<-tableGrob(x)

png("image1.png")
grid.arrange(p2, p1, main="Total Data and Image"
dev.off()

It works, but there seems to be a lot of space between p2 and p1. How can I have no or just little bit of space? Also, is there a way to make the font bigger on main?

thanks,

  • 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-04T08:47:01+00:00Added an answer on June 4, 2026 at 8:47 am

    This is not an answer.

    Your code is not reproducible. Wrapping your data in a read.table() function (and accepting default variable names), guessing that you are using base graphics, fixing typos in your code, and loading the gridExtra package (necessary for the grid.arrange function), I still cannot get your code to work. Using the ggplot2 package to draw the graph, I can get your code to work. The code is now reproducibe. See here for how to make a great reproducible example. And using my code, the result in my opinion looks pretty good. But it might not be what you intended. That’s why the community asks you to generate a reproducible example. All the better then to see what you mean by “a lot of space between p2 and p1”.

    But taking your workaround from your comment above – there are unnecessary elements in the code. You do not need both grid.arrange and arrangeGrob. Also, because you have the elements arranged side-by-side, I don’t think you need both widths and heights; widths alone is sufficient.

    library(ggplot2)
    library(gridExtra)
    
    x = read.table(text = "
    1/1/2010 10
    1/2/2010 20
    1/3/2010 15
    1/4/2010 56
    1/5/2010 46
    1/6/2010 15
    1/8/2010 15
    1/9/2010 15
    1/10/2010 20
    1/11/2010 15
    1/12/2010 15
    1/13/2010 40
    1/14/2010 15
    1/15/2010 15
    1/16/2010 70", sep = "", header = FALSE)
    
    p1<-ggplot(x, aes(V2, V1)) + geom_point()
    p2<-tableGrob(x)
    grid.arrange(p2, p1, main="Total Data and Image", ncol = 2)
    

    Your fix:

    grid.arrange(p2, p1, main="Total Data and Image", ncol = 2, widths=c(1,2))
    

    Edit
    Baptiste’s solution – see comments below:

      grid.arrange(p2, p1, main=textGrob("Total Data and Image", gp=gpar(cex=3)), ncol = 2,
       widths=unit.c(grobWidth(p2), unit(1,"npc") - grobWidth(p2)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I plan to create a table to store the race result like this: Place
I have a data structure that looks like this: Model Place primary key id
I have a table that looks basically like this: id | redirectid | data
i like to substitute new string 'MEMORY247' in place of 0.0MB,2GB,0Gb...strings for this i
I created a table Place in mysql. In this table there are three fields.
I have a table structure like this (vertical design). I can have unlimited number
I have a script in T-SQL that goes like this: create table TableName (...)
I would like to format my table like this: full width columns wider than
I have a table like this id item user slot I want the SLOT
I Created a table like this for indian railways project: CREATE TABLE IF NOT

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.