How can I export images in R in vector format with separate layers for text labels and the actual plot?
I am asking because I am preparing an article for publication and the editor requests that I
provide the highest quality, vector format, versions of [my] images (.ai, .eps, .psd).
They also state that
Text and labelling should be in a separate layer to enable editing during the production process.
I created my plots in ggplot2 and I managed to export them in vector format (svg since this format shows unlike eps semi-transparent shading). either with ggsave(“filename.svg”) or in one case where I added additional text with svg(“filename.svg”) and dev.off() (the reason why I do not use facets here is that in the real plot I add significance levels to individual panels)
library(ggplot2); library(cowplot); library(svglite)
data_set = structure(list(Target = c("Snodgrassella", "Snodgrassella", "ABPV",
"ABPV", "DWV", "DWV", "SBPV", "SBPV", "AmFV", "AmFV", "Gilliamella",
"Gilliamella"), Legend = structure(c(1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor"),
Estimate = c(69.6983166741774, 93.5474567104972, 12.5, 3.125,
0, 0, 6.25, 12.5, 0, 0, 90.625, 90.625), Nucleotide = structure(c(2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("RNA",
"DNA"), class = "factor")), row.names = c(7L, 8L, 9L, 10L,
15L, 16L, 21L, 22L, 23L, 24L, 31L, 32L), class = "data.frame")
RNA_data_set = subset(data_set, Nucleotide == "RNA")
DNA_data_set = subset(data_set, Nucleotide == "DNA")
RNA_plot <- ggplot(RNA_data_set, aes(x=Target, y=Estimate, fill = Legend))+
geom_bar(stat="identity", color = "black")+
xlab(NULL) +
theme(legend.position="none",
plot.margin = unit(x = c(0.25,0.25,0.25,1),"cm"))+
ylab("RNA")
DNA_plot <- ggplot(DNA_data_set, aes(x=Target, y=Estimate, fill = Legend))+
geom_bar(stat="identity", color = "black")+
xlab(NULL) +
theme(legend.position="none",
plot.margin = unit(x = c(0.25,0.25,0.25,1),"cm"))+
ylab("RNA")
svg("filename.svg")
plot_grid(RNA_plot, DNA_plot, nrow = 2)
grid.text(unit(0.03,"npc"),0.5, label = "Y-label (%)", rot = 90)
dev.off()
However, I do not know how to separate text/labels from the actual plot in different layers. Does anyone know how to do this?

