Skip to content

Instantly share code, notes, and snippets.

@jtilly
Created April 10, 2016 21:27
Show Gist options
  • Select an option

  • Save jtilly/4aafe9d0a97279e347e7bea7e70151a2 to your computer and use it in GitHub Desktop.

Select an option

Save jtilly/4aafe9d0a97279e347e7bea7e70151a2 to your computer and use it in GitHub Desktop.
Print graphs to screen and save them as Tikz or PDF
print_graph = function(g, type = NULL, filename = NULL, height = 6, width = 6, path = ifelse(type == "tikz", "tex", "pdf")) {
print(g)
if(!is.null(type)) {
if(type == "tikz") {
tikz(paste0(path, "/", filename), height = height, width = width)
print(g)
dev.off()
}
if(type == "pdf") {
pdf(paste0(path, "/", filename), height = height, width = width)
print(g)
dev.off()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment