I'm new to R and trying to show graphs and images on the same page with R.
I tried to use library(ggpubr)
and ggarrange()
function.
to import the images I used library(png)
and readPNG()
to import my images.
The end result i'm aiming for is something like this:
The code i used to create the panel is:
library(ggpubr)
library(png)
data("ToothGrowth")
bxp <- ggboxplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco")
dp <- ggdotplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco", binwidth = 1)
img1 <- readPNG("image1.png")
img2 <- readPNG("image2.png")
im_A <- ggplot() + background_image(img1) # tried to insert the image as background.. there must be a better way
im_B <- ggplot() + background_image(img2)
ggarrange(im_A, im_B, dp, bxp,
labels = c("A", "B", "C", "D"),
ncol = 2, nrow = 2)
of curse i inserted the images manually using power-point.
Thanks,