2016-03-18 57 views
-1

我是新来安排网格。下面是我自己的尝试,这是非常混乱的,首先网格似乎并没有对齐y轴(我希望桌子右下方的图)。其次,根据窗口大小,表格不能正确缩放到图形上。使网格安排 - 绘制多个重复图的ggplot2问题

这怎么解决?我可以在哪里获得更多有关对齐网格的更多信息?

表数据

> AAK.stats 

          NA 
    Observations 1811.0000 
    NAs    0.0000 
    Minimum   -0.0612 
    Quartile 1   0.0000 
    Median    0.0000 
    Arithmetic Mean 0.0008 
    Geometric Mean  0.0007 
    Quartile 3   0.0013 
    Maximum   0.0696 
    SE Mean   0.0003 
    LCL Mean (0.95) 0.0003 
    UCL Mean (0.95) 0.0013 
    Variance   0.0001 
    Stdev    0.0110 
    Skewness   0.9051 
    Kurtosis   5.9795 

代码

> grid.arrange(chart(AAK.strategy), tableGrob(t(AAK.stats))) 

输出

enter image description here

回答

3

several questions already上调整一个tableGrob的话题。我经常要问的问题是:你想如何调整大小?默认情况下,它调整行/列的大小,使所有文本都适合。这意味着表的固定物理尺寸。它可以手动调谐的,但是,以决定是否

  • alter the font size
  • set the sizes arbitrarily,例如与“空”单位,并希望文本将适合。有了这个策略,仍然需要决定每个行/列是否应该给予相等的空间,或者应该保持相对间距。

无论如何,让我们先从一个重复的例子,可重复性

library(gridExtra) 
library(ggplot2) 

p <- ggplot() 

t <- tableGrob(iris[1,], rows = NULL) 
grid.arrange(p,t) 

enter image description here

起见,在这种情况下我会调整的情节如下,

library(gtable) 
library(grid) 

g <- ggplotGrob(p) 
margin <- unit(0.5,"line") 
# allocate a new row to fit the table 
g <- gtable_add_rows(g, sum(t$heights) + margin) 
# locate the plot panel column 
panel <- g$layout[g$layout$name == "panel", "l"] 
# add the table 
g <- gtable_add_grob(g, t, nrow(g), panel) 
# set the plot panel width to the table's width 
g$widths[panel] <- list(sum(t$widths)) 
grid.newpage() 
grid.draw(g) 

enter image description here