Part 3: Do it Yourself

Author

Raeesa Ganey

Let the adventure begin

Ensure that you have:

  • A recent version of RStudio.

  • A working Quarto project (a fresh folder).

Level 1 - Basics

Create a new .qmd presentation file

Title, author, date in YAML

A simple slide with text

Add one code chunk that prints output

For example,

Your rendered slide,

Level 2 - Content

Load and display a built in R dataset

  • Bonus points: use knitr::kable() and DT::datatable() to display your data.

Embed a plot

For example writing this code chunk in your .qmd:

Code
library(biplotEZ)
bp <- biplot(iris,scale=TRUE) |> 
  PCA(group.aes=iris$Species) |> 
  axes(col="black") |> 
  samples(col=c("pink","orange","firebrick3"),opacity = 0.7) |>
  plot()

will give the following output:

Understand code chunk options

Every code block in Quarto (and R Markdown) starts with three backticks and curly braces. You can control how each chunk behaves using chunk options, which appear after the language name, R.

These options determine what appears in your final document, and what actually runs behind the scenes. Commonly used options are:

  • echo: controls whether the code itself is shown.
  • eval: controls whether the code is executed.
  • warning: show or hide warnings.
  • message: show or hide messages (e.g., package loading info).
  • results: controls how text results are displayed.

Level 3 - Interactivity

Turn any ggplot into an interactive widget: pan, zoom, tooltips, and export using ggplotly.

Code
p <- ggplot(mtcars, aes(hp, mpg, color = factor(cyl))) +
  geom_point(size = 3, alpha = 0.85) +
  geom_smooth(method = "lm", se = FALSE) +
  theme_minimal() +
  labs(
    title = "Fuel Efficiency vs Horsepower",
    x = "Horsepower", y = "Miles per Gallon", color = "Cyl"
  )
ggplotly(p)

Let’s try to make a 3D plot with plotly using an example from the plotly website.

Code
library(plotly)

mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)

fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E'))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
                     yaxis = list(title = 'Gross horsepower'),
                     zaxis = list(title = '1/4 mile time')))

fig

Let’s have a go at using the echarts4r package:

The echarts4r package brings the full power of Apache ECharts, a modern JavaScript visualisation library into R. It lets you build rich, interactive plots with zooming, panning, dynamic tooltips, animations, and built-in themes - all without leaving R.

Code
library(echarts4r)
Warning: package 'echarts4r' was built under R version 4.5.1
Code
iris |> 
  group_by(Species) |> 
  e_charts(Sepal.Length) |> 
  e_line(Sepal.Width) |> 
  e_lm(Sepal.Width ~ Sepal.Length) |> 
  e_x_axis(min = 4)

This is a basic example, but have a go using one of the examples on the echarts4r website.

Level 4 - Styling & Layout

Quarto lets you arrange content in columns, adjust styles, and create flexible, polished layouts that look great both in HTML documents and slides.

Add a two-column layout slide

Can you see the two distinct columns?

Try swapping the left/right content.

You can even change the column’s width!

Insert an image and caption

Experiment with slide transitions (revealjs options)

Back to the YAML, you can set the transition between slides and the speed for the whole deck:

Add incremental bullet points

Insert a callout or alert box

Other callout types

callout-note

callout-tip

callout-warning

callout-important

callout-example

Level 5 - Stretch

Add a custom theme (.scss or built-in Quarto theme)

Let’s first try a built-in Quarto theme.

Then of course you can have your own style file! A style file is any external file that controls the appearance (not the content or logic) of your document or slides. They tell Quarto how to render fonts, colors, spacing, headings, figure sizes, and other visual details.

The two main kinds of style files are

  • css: standard cascading stlye sheets - tweak fonts, margins, backgrounds, etc.
  • scss: smart “css” - supports variables and nesting used for theme customisation.

Here is a simple .scss file that Johané created: Download the file here. Try experimenting with the colours, fonts, and sizes - stretch your creativity and make it your own!

Then just let your YAML know to use your .cscc. It must be in the same directory as your .qmd.

Cheatsheets + check your answers

Check out some cool quarto cheatsheets

Check your answers

MDAG logo

To wrap up

Congratulations - you’ve built your first Quarto document from the ground up! Along the way, you’ve written text and code, created tables and plots, added interactivity, experimented with layouts, and even designed your own style file. You now have the essentials to produce fully reproducible, beautifully styled reports and presentations. Most importantly: Quarto is meant to be played with. Don’t be afraid to experiment!

Remember

Share your results — Quarto is made for open, collaborative science and teaching.