ragg_png = function(..., res = 150) {
  ragg::agg_png(..., res = res, units = "in")
}
knitr::opts_chunk$set(dev = "ragg_png")

Required packages

library(penngradlings)
library(ggplot2)
library(grid)
library(gridtext)

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)


yjunechoe/penngradlings documentation built on Sept. 6, 2024, 8:13 p.m.