How to combine imported image with other ggplots

Hello everyone ,

I have imported the image below and I would like to combine with some heatmap and ggplot2 plots .
But got errors while combing the image with other plots
May I get your help please

 my_image <- magick::image_read("Capture.PNG")
library(pheatmap)
test  <- matrix(rnorm(200), 20, 10)
mfs  <- pheatmap(test)

library(ggplot2)
library(dplyr)
 plot_LM <-  test %>% as.data.frame() %>%
    ggplot(aes(x=V1, y=V2)) +
    geom_point(color="blue") + 
    geom_smooth(method=lm, se=FALSE, fullrange=TRUE,
                linetype="dashed",
                color="darkred", fill="blue")

gridExtra::grid.arrange(grobs=list(mfs$gtable, plot_LM, my_image ), 
                         ncol= 3, labels=LETTERS[1:3])

Best,
Amare
Capture

I adapted the example from here:

library(ggplot2)
library(cowplot)
library(magick)

# Update 2020-04-15: 
# As of version 1.0.0, cowplot does not change the default ggplot2 theme anymore.
# So, either we add theme_cowplot() when we build the graph 
# (commented out in the example below), 
# or we set theme_set(theme_cowplot()) at the beginning of our script:
theme_set(theme_cowplot())

my_plot <- 
  ggplot(data    = iris, 
         mapping = aes(x    = Sepal.Length, 
                       fill = Species)) + 
  geom_density(alpha = 0.7) # +
# theme_cowplot()

img_plt <- ggdraw() +  draw_image("https://forum.posit.co/uploads/default/original/3X/0/8/08270ad040b087a935235cc2f36155ab96e01b11.png")
# Example with PNG (for fun, the OP's avatar - I love the raccoon)
plot_grid(my_plot,
          img_plt,
          my_plot,
          ncol = 3)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.