簡體   English   中英

在 grid.arrange 中增加 plot 的大小

[英]Increasing the size of plot in grid.arrange

我想要 plot 條形圖和它下面的表格,使用 ggplot2 並通過 Rmd 編織成文字。 但是,我需要我的 plot 大一點,我各自的表小一點。 當前代碼生成一個非常小的條 plot。下面是一個工作示例。

library(tidyverse)
library(grid)
library(gridExtra)

#plot

g <- ggplot(mpg, aes(class))
g<-g + geom_bar()

#table
dat<-mpg %>% count(class) %>% 
  t() %>%   
  as.data.frame() %>% 
  row_to_names(row_number = 1)


table <- tableGrob(dat)

#table and plot

plot2_fin<-grid.arrange(arrangeGrob(nullGrob(), g ,
                    widths=c(3,8)), 
arrangeGrob(arrangeGrob(nullGrob(),table, widths=c(3,18,1)),
                                    heights=c(1,1)))

plot2_fin

您可能會考慮從 grid 轉移到 cowplot

library(tidyverse)
library(grid)
library(gridExtra)

#plot

g <- ggplot(mpg, aes(class))
g<-g + geom_bar()

#table
dat<-mpg %>% count(class) %>% 
  t() %>%   
  as.data.frame() %>% 
  row_to_names(row_number = 1)


table <- tableGrob(dat)

#table and plot

library(cowplot)


plot_grid(g, table, 
          ncol = 1, 
          rel_heights = c(4, 1))

來自 cowplot 的示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM