Published and tested 22 November 2026.
Also blank the corresponding axis.ticks and axis.title elements when those should disappear. Apply these themes to each plot before wrap_plots(..., ncol=2). The example keeps coord_fixed() so every heatmap cell stays square.
Which labels remain in each panel?
Panel A keeps its y labels, panel B keeps neither axis's labels, panel C keeps both, and panel D keeps its x labels. Here A/B form the top row and C/D the bottom row. This leaves x labels under the bottom panels and y labels beside the left panels.
I use the lower-left panel as my reference because it keeps both axes. Then I can check which labels the neighbouring panels actually need.


What data and versions reproduce this result?
Use one nine-cell grid in four panels, with R 4.5.3, ggplot2 4.0.4 and patchwork 1.3.2.
This article uses simulated example data. One original nine-cell score grid is repeated in all four panels to isolate the layout change. Its rows from bottom to top are 2,5,8, 3,7,4, and 9,1,6. Scores are unitless values used to demonstrate layout.
Run Rscript --vanilla example.R with R 4.5.3, ggplot2 4.0.4 and patchwork 1.3.2. The script saves both complete PNGs at 1400 × 1200 pixels and the corrected PDF on a 7 × 6 inch page. It also writes the input CSV, axis inspection CSV and session information beside the script.
The PNGs use Windows Arial 7.03. The PDF names standard Helvetica without embedding a font file, so viewers may substitute a font. Other systems may render different lettering.
# Original Bopbun code and synthetic scores: CC0-1.0.
library(ggplot2)
library(patchwork)
out <- dirname(normalizePath(sub('^--file=', '', grep('^--file=', commandArgs(), value=TRUE)[1])))
d <- expand.grid(column=1:3, row=1:3)
d$score <- c(2,5,8,3,7,4,9,1,6)
write.csv(d, file.path(out,'synthetic.csv'), row.names=FALSE)
p <- ggplot(d,aes(column,row,fill=score)) +
geom_tile(colour='white',linewidth=0.7) +
geom_text(aes(label=score),colour='black',size=4) +
scale_fill_gradient(low='#eef6f4',high='#54aaa2',limits=c(0,9),guide='none') +
scale_x_continuous(breaks=1:3,labels=c('X1','X2','X3'),expand=c(0,0)) +
scale_y_continuous(breaks=1:3,labels=c('Y1','Y2','Y3'),expand=c(0,0)) +
coord_fixed() + labs(x='Column',y='Row') +
theme_minimal(base_size=12) + theme(panel.grid=element_blank())
plots <- lapply(LETTERS[1:4],function(s) p + labs(title=paste('Panel',s)))
before <- wrap_plots(plots,ncol=2)
no_x <- theme(axis.text.x=element_blank(),axis.ticks.x=element_blank(),axis.title.x=element_blank())
no_y <- theme(axis.text.y=element_blank(),axis.ticks.y=element_blank(),axis.title.y=element_blank())
after <- wrap_plots(plots[[1]]+no_x,plots[[2]]+no_x+no_y,
plots[[3]],plots[[4]]+no_y,ncol=2)
ggsave(file.path(out,'before.png'),before,width=7,height=6,units='in',dpi=200,bg='white')
ggsave(file.path(out,'after.png'),after,width=7,height=6,units='in',dpi=200,bg='white')
ggsave(file.path(out,'after.pdf'),after,width=7,height=6,units='in',bg='white',timestamp=FALSE)
# Inspect non-empty axis/title grobs in each constituent ggplot.
pdf(NULL) # Supply a metrics device without creating a default Rplots.pdf.
visible <- function(plot,name) {
g <- ggplotGrob(plot)
ids <- which(g$layout$name==name)
any(vapply(g$grobs[ids],function(x) !inherits(x,'zeroGrob'),logical(1)))
}
final <- list(plots[[1]]+no_x,plots[[2]]+no_x+no_y,plots[[3]],plots[[4]]+no_y)
check <- do.call(rbind,lapply(1:4,function(i) data.frame(panel=LETTERS[i],
x_axis=visible(final[[i]],'axis-b'),y_axis=visible(final[[i]],'axis-l'),
x_title=visible(final[[i]],'xlab-b'),y_title=visible(final[[i]],'ylab-l'))))
# Axis containers can remain even when text/ticks are blank. Check resolved themes too.
check$x_text <- vapply(final,function(x) !inherits(x$theme$axis.text.x,'element_blank'),logical(1))
check$y_text <- vapply(final,function(x) !inherits(x$theme$axis.text.y,'element_blank'),logical(1))
write.csv(check,file.path(out,'axis-check.csv'),row.names=FALSE)
invisible(dev.off())
sink(file.path(out,'session-info.txt')); print(sessionInfo()); sink()
print(check)
When should the inner labels stay visible?
Keep each panel's labels when category names, category order or scale meaning differ. Synchronize scales and category order before hiding labels. This example sets matching breaks, labels and fill limits before hiding anything. Patchwork's axes="collect" offers automatic collection of duplicate axes; its layout scope and fixed-aspect behavior should be checked for the actual plots. This manual method specifies exactly which axis text is shown without diagnosing a third-party plotting wrapper.
Which files can I download?
Download the complete R script, input and inspection CSVs, both PNGs, the PDF, license and file hashes below.
These are the code, data and result files used in this article. Choose a file below to run the example or compare your results.
- example.RComplete example code to run on your computer.
- synthetic.csvThe input data used in the example; open it as a table.
- axis-check.csvAxis labels and titles for each panel.
- layer-check.csvThe data drawn in each plot panel.
- before.pngThe figure before the change, for comparison.
- after.pngThe figure after applying the settings in this article.
- after.pdfThe result in PDF format, for viewing and page layout.
- Usage license · LICENSE.txtTerms for reusing the code, data and figures, with source and font notices.
File verification
- hashes.jsonChecksums for checking whether the downloaded files are complete.
Which sources and reuse terms apply?
Original code, synthetic scores and figure composition are CC0-1.0. R 4.5.3 retains GPL-2 or GPL-3; ggplot2 4.0.4 and patchwork 1.3.2 retain their MIT notices. Install the required dependencies and fonts separately before running the example.
The selected Stack Overflow question shows 18 November at 13:33; its year and timezone are unknown. It reports a ggcorrplot-specific collection issue. This tutorial uses original scores and explicit theme settings to control label visibility. The patchwork documentation page is version 1.3.2.9000; execution used 1.3.2.
Which related layout answer should I use?
Separate-file alignment, facet-specific brackets and figure size calculations have dedicated answers linked below.
Learn R

