Skip to content

Instantly share code, notes, and snippets.

@baptiste
Last active September 18, 2018 09:39
Show Gist options
  • Save baptiste/a514b9453059da40bdcdae7eb9889fa1 to your computer and use it in GitHub Desktop.
Save baptiste/a514b9453059da40bdcdae7eb9889fa1 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(gridExtra)
library(grid)
library(tikzDevice)
chem <- "\\setatomsep{1em}\\chemfig{*6(-=-=(-[:90]N-[:30](=[:90]O)-[:-30](=[:-90]O)-[:30]N-[:-30]-[:30]-[:-30]N-[:30](=[:90]O)-[:-30](=[:-90]O)-[:30]N-[:-30](-[:-90]-[:-30](-[:30])-[:-90])-[:30](=[:90]O)-[:-30]O-[:30])-*6(-(=O)-*6(-=-=-=)--(=O)-)=)}"
p <- ggplot() + xlab('some chemistry') + ylab("some value") +
theme(plot.background = element_rect(colour = 'black', fill=NA),
plot.tag = element_text(margin=margin(0,0,0,0)),
plot.tag.position = c(0,1))
tikz(file = 'test.tex', standAlone = TRUE, width = 6, height=4,
engine = 'xetex', bareBones = FALSE,
packages = c("\\usepackage{chemfig}",
"\\usepackage{preview}",
"\\usepackage[default,osf]{sourcesanspro}"))
grid.arrange(grobTree(rectGrob(),
textGrob("\\textbf{a}", vjust=1,hjust=0,x=0,y=1,
gp=gpar(fontsize=14)),
textGrob(chem)),
p + labs(tag = "\\textbf{b}"),
p + labs(tag = "\\textbf{c}"),
layout_matrix = cbind(c(1,2),c(3,3)),
heights = c(2,5))
dev.off()
@baptiste
Copy link
Author

screen shot 2018-09-18 at 9 38 46 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment