library(dagitty)
library(ggplot2)
library(ggdag)
get_jpg <- function(filename) {
grid::rasterGrob(jpeg::readJPEG(filename), interpolate = TRUE)
}
logo <- get_jpg("logo.jpg")
ex.1 <- dagitty("dag {
X <- A -> B <- C -> Y
X <- B -> Y
X -> W -> Y
S-> T -> C
}")
exposures(ex.1) <- 'X'
outcomes(ex.1) <- 'Y'
tidy.1 <- ex.1 %>%
tidy_dagitty() %>%
mutate(label = str_to_upper(name))
ggdag(tidy.1 , text = FALSE, use_labels = "label") + theme_dag() +
theme_light() +
annotation_custom(logo, xmin = 6.5, xmax = 8.5, ymin = -5, ymax = -8.5) +
coord_cartesian(clip = "off") +
theme(plot.margin = unit(c(1, 1, 3, 1), "lines"))
I have this code to put a JPG image within my plot. I understand that the xmin, xmax, ymin ymax coordinates are not aligning. Is there a way where I can display the image on the bottom right of the graph (similar to the ones shown here: https://www.markhw.com/blog/logos)? I want to do this dyanmically if possible without specifying coordinates because I'm not sure how ggdag plots x and y coordinates for the causal graphs.
Thanks!

