R语言 如何使用magick添加多个图像到ggplot 2?

3lxsmp7m  于 2022-12-05  发布在  其他
关注(0)|答案(1)|浏览(144)

iam very new to R and having difficulties to add several images to my plot. Adding a single picture works perfectly fine by using the following code:

`add_image_centre <- function(plot_path, image_path) {
 fig <- image_read(plot_path)
 fig <- image_resize(fig, "1000x1000")
 img <- image_read(image_path)
 img <- image_scale(img, "62x85")
 image_composite(fig, img, offset = "+387+442") 
 }
 imagepl <- add_image_centre(plot_path = ".png", image_path = ".png") 
 imagepl 

 image_write(imagepl, ".png")
 `

How can i add several images this way?
I have tried copying the code but then it just changes to the last picture added and removes the first one.

k7fdbhmy

k7fdbhmy1#

简单地说

可以按如下方式并排合并figimg

image_append( c( fig, img ))

参考

请参阅https://rdrr.io/cran/magick/f/vignettes/intro.Rmd处的Combining部分,也如下所示:

require( magick )

bigdata <- image_read('https://jeroen.github.io/images/bigdata.jpg')
frink   <- image_read("https://jeroen.github.io/images/frink.png")

# Appending means simply putting the frames next to each other:
image_append(image_scale(img, "x200"))

# Use stack = TRUE to position them on top of each other:
image_append(image_scale(img, "100"), stack = TRUE)

# Composing allows for combining two images on a specific position:
# It also and flattens the image, losing information about which pixel came from
# which layer.

bigdatafrink <- image_scale(
    image_rotate(
      image_background( frink, "none" ), 300
    )
  , "x200"
)

image_composite(
    image_scale( bigdata, "x400" )
  , bigdatafrink
  , offset = "+180+100"
)

相关问题