Created
October 5, 2022 18:44
-
-
Save zachcp/f4cca1f8d4878df2c54eb43659bff472 to your computer and use it in GitHub Desktop.
Molecule in GGPlot Via SVG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(depict) | |
library(grid) | |
library(ggplot2) | |
library(svgparser) | |
# SVG code to make background box transparent | |
my_css = ' | |
rect { | |
fill: none; | |
fill-opacity: 50%; | |
} | |
' | |
mgrd <- depiction() %>% | |
depict::set_zoom(3) %>% | |
depict(parse_smiles("B([C@H](CC(C)C)NC(=O)[C@H](CC1=CC=CC=C1)NC(=O)C2=NC=CN=C2)(O)O")) | |
img_grob <- svgparser::read_svg( | |
mgrd$toSvgStr(), | |
user_css = my_css | |
) | |
ggplot(mtcars) + | |
geom_point(aes(mpg, wt)) + | |
annotation_custom(img_grob, xmin = 26, xmax = 33, ymin = 4, ymax = 5) + | |
labs(title = "svgparser::read_svg() + ggplot2") + | |
theme_bw() | |
Author
zachcp
commented
Oct 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment