0

I am trying to plot a table together with some graphs as part of par(mfrow=c(2,3)). I have 5 ggplot graphs and I would like the 6th part of these multiple plots to be filled with a table. However the table is exceeding its boundaries. See picture below:

enter image description here

This is the data for one out of 3 tables:

cov_table_1<-
structure(list(Year = structure(1:11, .Label = c("1970", "1971", 
"1972", "1973", "1974", "1975", "1977", "1979", "1980", "1981", 
"1982", "1983", "1984", "1985", "1986", "1987", "1988", "1990", 
"1991", "1992", "2000", "2001", "2003", "2004", "2007", "2008", 
"2009", "2010", "2011", "2012", "2013", "2014"), class = "factor"), 
`Percentage 
of missing data` = structure(c(4L, 2L, 4L, 6L, 
1L, 12L, 5L, 21L, 21L, 11L, 10L), .Label = c("0%", "1%", 
"100%", "17%", "24%", "31%", "35%", "5%", "58%", "59%", "60%", 
"70%", "71%", "72%", "8%", "86%", "90%", "92%", "95%", "98%", 
"99%"), class = "factor")), .Names = c("Year", "Percentage \nof missing data"
), row.names = c(NA, 11L), class = "data.frame") 

This is how I try to plot the 5 graphs and 1 table:

par(mfrow=c(2,3))
require(gridExtra)
library(RGraphics)
require(caroline)
require(ggplot2)
enter code here
h1<-ggplot() # graph 1
h2<-ggplot() # graph 2
h3<-ggplot() # graph 3
h4<-ggplot() # graph 4
h5<-ggplot() # graph 5
h6<-
# First I create an empty graph with absolutely nothing :
qplot(1:10, 1:10, geom = "blank",ylim=c(1,10), main=("\n")) + 
theme_void() +
# Then I add my table :
annotation_custom(grob = tableGrob(cov_table_1, rows=NULL), xmin=0, xmax=4,ymin=1, ymax=10)+
annotation_custom(grob = tableGrob(cov_table_2, rows=NULL), xmin=4, xmax=6,ymin=1, ymax=10)+
annotation_custom(grob = tableGrob(cov_table_3, rows=NULL), xmin=6, xmax=10,ymin=1)+
theme(plot.margin = unit(c(1,1,1,1), "cm"))

As you can see I tried shifting the tables by adding in a title: main("\n") and working with plot margin or ymin / ymax also didn't do the trick. Does anyone have an idea on how to handle this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
T. BruceLee
  • 501
  • 4
  • 16
  • A quick search brings up this answer (which I had forgotten myself): http://stackoverflow.com/questions/19934523/text-alignment-and-font-size-in-gtable – IRTFM Nov 24 '16 at 17:21
  • ftp://cran.r-project.org/pub/R/web/packages/gridExtra/vignettes/tableGrob.html shows a couple of way s of decreasing cell width and height as well as text size. – user20650 Nov 24 '16 at 17:50
  • https://github.com/baptiste/gridextra/wiki#problems-with-gridtable – baptiste Nov 24 '16 at 18:30
  • I used `tableGrob(table, rows=NULL,theme = ttheme_default())` to adjust the proportions of width to height (**`padding`**) and the size of the text and cells (**`base_size`**). Wherein: `ttheme_default(base_size = 10, padding = unit(c(4,2),"mm"))` – T. BruceLee Nov 24 '16 at 23:51

0 Answers0