Add Image to Plot in R (Example) | Draw Picture on Top of Graph Using ggplot2 & patchwork Packages

preview_player
Показать описание


R code of this video:

y = 10:5)

library("ggplot2") # Load ggplot2 package

ggp <- ggplot(data, aes(x, y)) + # Create ggplot2 plot
geom_point()
ggp # Draw ggplot2 plot

library("png") # Load png package

library("patchwork") # Load patchwork

ggp_image <- ggp + # Combine plot & image
inset_element(p = my_image,
left = 0.5,
bottom = 0.55,
right = 0.95,
top = 0.95)
ggp_image # Draw combined plot

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

thanks, Joachim, that was very useful!

yuzaR-Data-Science
Автор

Through this video, I managed to upload photos in R plots (I could do that before because I was not including image name and type).
You rock Joachim💪!!

agsoutas
Автор

Thanks, I needed to know how to do that for png merging for some bundle image automation ! You rock !

Ohmful
Автор

How would you get the image to sit at the bottom right? I am finding that changing the parameters just makes my image smaller or flips it upside down :)

tomd
Автор

Hi I tried to use this code to add an image to one of my plots however I ran into some errors and was wondering if you had any idea what the issue could be. I’m not a whiz at R so I struggle to interpret what errors are referring to some of the time. In the section where you combine the plot and image I have an error stating ‘non-numeric argument to binary operator’, and in addition ‘incompatible methods’. I did find that my_image came up as a large nativeraster which was different from your code, so maybe that’s the issue? Cheers!

lilylollielegs
Автор

Hi, I add images logo on geom_sf map with geom_image fonction but this doesn't work when add ggplotly, how can I do this 🥺

undzmoi
Автор

How can you add plot to a ggplot title? Thanks

jamesleleji