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()Ensure that you have:
A recent version of RStudio.
A working Quarto project (a fresh folder).
For example,
Your rendered slide,
R datasetknitr::kable() and DT::datatable() to display your data.For example writing this code chunk in your .qmd:
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:
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.Turn any ggplot into an interactive widget: pan, zoom, tooltips, and export using ggplotly.
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.
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')))
figLet’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.
library(echarts4r)Warning: package 'echarts4r' was built under R version 4.5.1
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.
Quarto lets you arrange content in columns, adjust styles, and create flexible, polished layouts that look great both in HTML documents and slides.
Can you see the two distinct columns?
Try swapping the left/right content.
You can even change the column’s width!
Back to the YAML, you can set the transition between slides and the speed for the whole deck:
callout-note
callout-tip
callout-warning
callout-important
callout-example
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.
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!
Share your results — Quarto is made for open, collaborative science and teaching.