Home > database >  How to place multiple pngs on a plot in R?
How to place multiple pngs on a plot in R?

Time:03-03

Similar questions have been asked graph with png

But what Im trying to do is place the png on every single tile go the heatmap. Now, I can retrieve the coordinates for each tile like so:

b <- ggplot_build(p)
b$data[[1]]$xmin
b$data[[1]]$xmax
b$data[[1]]$ymin
b$data[[1]]$ymax

But I don't know how to place the png on every tile. I was hoping to not have to have an annotation_custom argument for every single tile. I'm trying to somewhat automate the process.

Is there any way that this can be done?

CodePudding user response:

You can add the annotations in a loop

xmin = b$data[[1]]$xmin
xmax = b$data[[1]]$xmax
ymin = b$data[[1]]$ymin
ymax = b$data[[1]]$ymax

for (i in seq_len(nrow(data))) {
  p = p   annotation_custom(g, xmin = xmin[i], xmax = xmax[i], 
                               ymin = ymin[i], ymax = ymax[i])
}

enter image description here

  • Related