Quarto Annotation

R Workshop
Author
Affiliation

Boston University

Published

February 6, 2025

If we want to enable line numbering we need to add to the header a code-line-numbers option.

Annotation Syntax

Steps to enable annotations:

  1. Each annotated line should be terminated with a commentsymbol # followed by a space and then an annotation number enclosed in angle brackets (e.g. # <2> ). You may repeat an annotation number if the annotation spans multiple lines.

  2. An ordered list that appears immediately after the code cell which includes the contents of each annotation. Each numbered item in the ordered list will correspond to the line(s) of code with the same annotation number.

library(ggplot2)
data(airquality)

ggplot(airquality, aes(Temp, Ozone)) +
  geom_point() +
  geom_smooth(method = "loess"
)
1
Load ggplot2 library
2
Use the airquality dataset
3
Plot Temp and Ozone variables
Figure 1: Temperature and ozone level.

By default, code annotation text will appear below the code cell.

If you add code-annotations: hover to the header, the code annotation text will be displayed when the user hovers over the annotation marker

If you add code-annotations: select to the header, the code annotation text will be displayed when the user clicks on an annotation marker (selecting it). The annotation text can be dismissed by clicking the annotation marker once again.