Two much white space between plots on grid

I want to arrange png images in a grid and label them figures as (a), (b) and (c) but my code creates a lot of white space between the bottom two :

image

I don't think it's possible via knitr directly. So I tried grid and gridExtra:

```{r fig-mlgrid, echo= FALSE}
#| fig.cap: "(a) Histogram (b) Relationship with pore size (c) Conductivity"
#| out.width: "100%"
#| fig.align: "center"
#| fig.subcap: !expr c("", "")

library(png)
library(grid)
library(gridExtra)

image1 <- readPNG("images/rectangle.png") #Plot 3 in the attached figure. 
image2 <- readPNG("images/square1.png") #Plot 1
image3 <- readPNG("images/square2.png") #Plot 2

row1 <- rasterGrob(image1)
row2 <- arrangeGrob(rasterGrob(image2), rasterGrob(image3), ncol = 2)

a <- textGrob("(a)", x = 0.5, y = 0.5, just = "center", gp = gpar(fontsize = 10))
bc <- arrangeGrob(
  textGrob("(b)", x = 0.5, y = 0., just = "center", gp = gpar(fontsize = 10)), 
  textGrob("(c)", x = 0.5, y = 0., just = "center", gp = gpar(fontsize = 10)),
  ncol = 2, padding = unit(0, "line"),
  heights = unit.c(unit(0.1, "cm"))
)

grid.arrange(
  row1, a,
  row2, bc,
  #ncol = 1,
  heights = unit.c(unit(1, "null"), unit(0.35, "null"), unit(1, "null"), unit(0.35, "null"))

)

How do I reduce the white space?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.