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,
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 thegridExtrapackage (necessary for thegrid.arrangefunction), I still cannot get your code to work. Using theggplot2package 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.arrangeandarrangeGrob. Also, because you have the elements arranged side-by-side, I don’t think you need bothwidthsandheights;widthsalone is sufficient.Your fix:
Edit
Baptiste’s solution – see comments below: