SoFunction
Updated on 2025-03-01

R language ggplot2 implements splicing multiple photos together

Stitch multiple photos together, but ps and ai are not installed on the computer (I only think of these two software for the time being)

Use R language directly

The idea is to read pictures

Use ggplot2 to display

Finally, patchwork is used

Code

library(ggplot2)
library(jpeg)
library(ggpubr)

library(patchwork)

img0<-readJPEG("308/")
p0<-ggplot()+
  background_image(img0)+
  theme_void()

img1<-readJPEG("308/")  
p1<-ggplot()+
  background_image(img1)+
  theme_void()

img2<-readJPEG("308/")
p2<-ggplot()+
  background_image(img2)+
  theme_void()

img3<-readJPEG("308/")
p3<-ggplot()+
  background_image(img3)+
  theme_void()

img4<-readJPEG("308/")
p4<-ggplot()+
  background_image(img4)+
  theme_void()

p1234<-p1+p2+p3+p4+plot_layout(ncol = 4)


img5<-readJPEG("308/")  
p5<-ggplot()+
  background_image(img5)+
  theme_void()

img6<-readJPEG("308/")
p6<-ggplot()+
  background_image(img6)+
  theme_void()

img7<-readJPEG("308/")
p7<-ggplot()+
  background_image(img7)+
  theme_void()

img8<-readJPEG("308/")
p8<-ggplot()+
  background_image(img8)+
  theme_void()

p5678<-p5+p6+p7+p8+plot_layout(ncol=4)

p_final<-p0+p1234+p5678+plot_layout(ncol=1,nrow=3,
                                    heights  = c(3,1,1))

ggsave(filename="",
       p_final,
       width=12,
       heigh=15,
       dpi = 1000)

This is the article about R language ggplot2 implementing splicing multiple photos together. For more related content on R language ggplot2 multi-photo splicing, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!