Skip to content
Prev 5396 / 5632 Next

[R-meta] Two large forest plots in one image

Dear Guido,

Apologies for the late reply.

I have been trying to work it out with your code, but unfortunately,
it was not coming out nicely.

However, I managed to use the {magik} package to work around it with
visually appealing images.

Kindest regards,

Emanuel



Below is the code:

Save each forest plot using the Plots -> Export -> Save as Image.

Save each forest plot in png format using a constant width of 950 and
an appropriate height so they fit well.



library(magick)



# Load the images

img1 <- image_read("image_1.png")

img2 <- image_read("image_2.png")

img3 <- image_read("image_3.png")



# Annotate each image with a letter

img1_annotated <- image_annotate(img1, "A", size = 40, gravity =
"northwest", color = "black")

img2_annotated <- image_annotate(img2, "B", size = 40, gravity =
"northwest", color = "black")

img3_annotated <- image_annotate(img3, "C", size = 40, gravity =
"northwest", color = "black")



# Display the annotated images (optional)

img1_annotated

img2_annotated

img3_annotated



# Combine images into a grid

combined_image <- image_append(c(img1_annotated,
img2_annotated,img3_annotated), stack = TRUE)



# add extra white space around the combined plot

padded_legend <- image_border(combined_image, color = "white",
geometry = "50x20")

padded_legend



# Save the combined image

image_write(padded_legend, path = "combined_plots_123.png")


On Mon, Jul 29, 2024 at 5:49?PM Dr. Guido Schwarzer
<guido.schwarzer at uniklinik-freiburg.de> wrote:
Message-ID: <CAE89KOOHwkwEURR7W2HSHeWFdb00fqW2a1AGk1+xO02QNyfBcQ@mail.gmail.com>
In-Reply-To: <4E61F6C3-EC35-4C6F-AF4C-864A7AF431A6@uniklinik-freiburg.de>