Skip to contents

Required packages

HTML textbox annotations with annotation_textbox

p <- ggplot(mtcars, aes(mpg, hp)) +
  geom_point()

p

annotation <- "
  <span style=\"font-size:18px; font-family:'Piazzolla-Black';\">
   This is a cat:</span>
  <br><br>
  <span style=\"font-size:72px; color:'#7950F2';
   font-family:'FontAwesome5-Solid';\">cat</span>
  <br><br>
  Just look at this
  <span style=\"font-family:'PiazzollaSC-Regular';\">cat!</span>
"

tbox1 <- annotation_textbox(
  html = annotation,
  position = "top-right",
  halign = 0.5,
)

p + annotation_custom(tbox1)

tbox2 <- annotation_textbox(
  html = annotation,
  position = "center",
  halign = 0.5,
  valign = 0.5,
  x_offset = -0.1,
  y_offset = 0.1,
  width = 0.4,
  height = 0.5
)

p + annotation_custom(tbox2)