这里的目标是使用magick read和带注释的图像以网格方式设置图像。我可以读取、注释图像,并以3列为一组(即3列)。我只是想不出如何将这些组堆叠在一起。这是预期的结果,但不灵活(?)而且image_ggplot()慢得让人痛苦:
grid.arrange(image_ggplot(annotated_images[[1]]),image_ggplot(annotated_images[[2]]),
image_ggplot(annotated_images[[3]]),image_ggplot(annotated_images[[4]]),
image_ggplot(annotated_images[[5]]),image_ggplot(annotated_images[[6]]),
image_ggplot(annotated_images[[7]]),image_ggplot(annotated_images[[8]]),
image_ggplot(annotated_images[[9]]),image_ggplot(annotated_images[[10]]),
image_ggplot(annotated_images[[11]]),ncol=3)下面是我从地面开始构建它的尝试:
newlogo <- image_read("https://jeroen.github.io/images/Rlogo.png")
images=rep(newlogo,11)
chunk_images=split(images, ceiling(seq_along(images)/3))
annotated_images=lapply(images,function(x){
image_annotate(image_read("https://jeroen.github.io/images/Rlogo.png"), paste0('Random Number: ',rnorm(1)), color = 'white',boxcolor='grey10', size = 23)
})
list_of_rows=lapply(chunk_images,function(x){image_append(c(image_annotate(x, paste0('Random Number: ',rnorm(1)), color = 'white',boxcolor='grey10', size = 23)))})
#list_of_rows[1] == 3 images side-by-side
#list_of_rows[2] == 3 images side-by-side
#list_of_rows[3] == 3 images side-by-side
#list_of_rows[4] == the remaining 2 images我想要将list_of_rows堆叠在一起,这两个都不起作用:
lapply(list_of_rows,function(x){image_append(x,stack=T)})
do.call(c,list_of_rows)只是寻找一种灵活的方式来安排在我可以控制的列数从4-32个图像的任何地方(不会知道每次图像的总数)。
发布于 2020-11-13 01:12:37
正如@fmw42在评论中所建议的,您可以使用函数image_montage和tile parameter来控制列的排列
newlogo <- "https://jeroen.github.io/images/Rlogo.png"
images=rep(newlogo,11)
img <- magick::image_read(images) %>%
magick::image_montage(tile = '3')https://stackoverflow.com/questions/61801420
复制相似问题