Home > Software engineering >  Is there an option to ad a black border to a image nested in a ggdraw?
Is there an option to ad a black border to a image nested in a ggdraw?

Time:03-31

library(cowplot)
ggdraw()  
    draw_plot(p)  
  draw_image(magick::image_read("img.png"),
             scale = .25, x = .4, y = .1)

Here p is not even important, I would just like to add a black border to img.png.

CodePudding user response:

library(cowplot)
library(magick)

tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 350)

ggdraw()  
  draw_image(
    tiger,
    scale = .5, x = -0.25, y = 0.25
  )  
  draw_image(
    tiger |> magick::image_border(color = 'black'),
    scale = .5, x = 0.25, y = 0.25
  )  
  draw_image(
    tiger |> magick::image_border(color = 'firebrick'),
    scale = .5, x = -0.25, y = -0.25
  )  
  draw_image(
    tiger |> magick::image_border(color = 'navy'),
    scale = .5, x = 0.25, y = -0.25
  )

enter image description here

  • Related