Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active October 24, 2022 10:07
Show Gist options
  • Save knbknb/f2e2c635fc7ec656efac39cf94d7f68c to your computer and use it in GitHub Desktop.
Save knbknb/f2e2c635fc7ec656efac39cf94d7f68c to your computer and use it in GitHub Desktop.
R: save plot as SVG
library(ggplot2)
# save an image object created with "ggplot2" to svg file
# runs on linux
myplot_svg <- "myplot.svg"
image <- ggplot() +
geom_col(aes(x= symb,y=v,fill=symb))+
theme(axis.text.x = element_text(angle=90)) +
labs(title='Some title', subtitle=sprintf('%s',date())) +
facet_wrap(~ k, scales='free');
ggsave(filename=myplot_svg, plot=image, width=10, height=8)
# optional
# system(glue::glue('firefox "{myplot_svg}" &')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment