Hi All,
I have a peculiar problem, and writing here after many workarounds and still not making perfect multi-panel figures in svg or pdf format. Before assembly into muti-panel figures, the plots look fine.
Once assembled, the individual plots have a slight off-set of the top side of the box plot to the right. It looks like an indentation int the top left corner:
I am able to save ggplot2 box plots as svgs that look fine and close to png format. Once I import them back for assembly (workaround, since I need to combine figs from multiple sources) i have to do it as grobs with grImport2 package like so:
# Loop through the SVG files and read them into the list as grobs
for (i in 1:length(svg_files)) {
svg_plot <- readLines(svg_files[i])
pic <- grImport2::readPicture(file = svg_plot)
grob <- grImport2::pictureGrob(pic)
plots[[i]] <- grob
}
To save these plots prior to importing I have to use Cairo, otherwise I can not assemble into multi-panel like so:
# Save plot as SVG
ggsave("box_plot.svg", plot = p2, width = 3, height = 1.8, device = CairoSVG)
The assembly does not seem to be affecting this, as I have used Cowplot or gridExtra, and Cairo or svg, or pdf device with the same results. Here is the example code for saving final output:
svg(file = "Fig1_multiplot_panel.svg", width = 10, height = 11)
# Combine the plots into a single figure
combined_plot <- plot_grid(plotlist = plots, ncol = 3, align = "h", axis = "tb", labels = NULL)
combined_plot
dev.off()
Thank you.