Demo Lab

RaukR 2025 • R Beyond the Basics

This is a demo quarto lab document to showcase the theme, style and usage.
Author

Roy Francis

Published

08-May-2025

This is a quarto document

1 Text formatting

1.1 Headings

## Level 2 heading  
### Level 3 heading  
#### Level 4 heading  
##### Level 5 heading  
###### Level 6 heading

1.2 Character sizes

Custom character sizes. This is an enchanced feature.

Markdown Rendered
[Largest text]{.largest} Largest text
[Larger text]{.larger} Larger text
[Large text]{.large} Large text
Normal text Normal text
[Small text]{.small} Small text
[Smaller text]{.smaller} Smaller text
[Smallest text]{.smallest} Smallest text

1.3 Character styles

Markdown Rendered
__Bold text__ Bold text
_Italic text_ Italic text
~~Strikethrough~~ Strikethrough
H~2~O H2O
x^2 x^2
--
---
[link](r-project.org) link
{{< kbd Shift-Ctrl-P >}}

Shift-Ctrl-P

1.4 Blockquote

> This is a block quote. This
> paragraph has two lines.
>
> 1. This is a list inside a block quote.
> 2. Second item.

This is a block quote. This paragraph has two lines.

  1. This is a list inside a block quote.
  2. Second item.

1.5 Line block

Line block preserves spaces and new lines.

| This
|     block
|          preserves
|                   formatting
This
    block
         preserves
                  formatting

1.6 Rule

A horizontal line can be created using three or more * or -.

***


1.7 Footnote

An example of footnote reference 1

1.8 Aside

[This content lives in the right margin]{.aside}

This content lives in the right margin

1.9 Badge

Badges are defined as such:

[badge]{.badge .badge-primary} badge
[badge]{.badge .badge-secondary} badge

2 Code formatting

Verbatim code is text formatted using monospaced font intended as code. Verbatim code can be defined inline where `date()` looks like date().

Code can also be defined inside code blocks.

```
date()
```
date()

Source code, ie; code that is highlighted or executed in a quarto document is not covered here.

3 Code execution

Code can be defined inline where `r Sys.Date()` renders 2025-05-19.

Code can be defined inside code blocks.

```{r}
Sys.Date()
```

which shows the source code and output.

Sys.Date()
[1] "2025-05-19"

Here is another example of executed R code with input and output.

data(iris)
head(iris[, 1:2])

4 Chunk attributes

Properties and behaviour of code chunks can be controlled using chunk attributes. This is specified as comment sign of the language and pipe followed by key: value. So for example, in R: #| eval: false.

In this example, the R source code and results are hidden but the code is evaluated.

```{r}
#| eval: true
#| echo: false
#| results: hide
Sys.Date()
```

A code chunk can be given a code filename using the chunk attribute filename.

```{r}
#| filename: R code
Sys.Date()
```
R code
Sys.Date()

Enable line numbers using code-line-numbers: true.

```{r}
#| code-line-numbers: true
Sys.Date()
sessionInfo()
```
Sys.Date()
sessionInfo()

An advanced example showing bash code generated from R.

```{r}
#| attr-output: "filename='bash'"
#| class-output: bash
#| echo: false
d <- "custom"
cat(paste("mkdir​", d))
```
bash
mkdir<U+200B> custom

Code chunk attributes are documented here.

5 Lists

5.1 Unordered

Unordered lists are created using dashes.

- Bullet 1
- Bullet 2
  - Sub-bullet 2.1
  - Sub-bullet 2.2
- Bullet 3
  • Bullet 1
  • Bullet 2
    • Sub-bullet 2.1
    • Sub-bullet 2.2
  • Bullet 3

5.2 Ordered

Ordered lists are created using numbers.

1. Point 1
2. Point 2
3. Point 3
  1. Point 1
  2. Point 2
  3. Point 3

5.3 Multiple Lists

::: {}
1. Point 1
2. Point 2
:::

:::{}
1. Point 1
2. Point 2
:::
  1. Point 1
  2. Point 2
  1. Point 1
  2. Point 2

6 Images

Images can be inserted using plain markdown or HTML directly. Plain markdown can be embellished with custom quarto adjustments to modify aspects of the image. Clicking the image opens the image in a lightbox. This is made possible using the lightbox extension.

6.1 Using Markdown

Using regular markdown.

![](assets/image.webp)

The dimensions are based on image and/or fill up the entire available space. You can control the dimension as shown below.

![This is a caption](assets/image.webp){width=30%}  

This is a caption

This is a caption

This image above is now 30% of it’s original width.

6.1.1 Figure layout

::: {#fig-mylabel layout-ncol=2}
![Caption for figure 1](assets/image.webp){width="40%"}

![Caption for figure 2](assets/image.webp){width="40%"}

These figures are interesting.
:::

Caption for figure 1

Caption for figure 2
Figure 1: These figures are interesting.

More figure options and layouts are described here. Cross referencing described here.

6.2 Using HTML

This image below is 30% size.
<img src="assets/image.webp" style="width:30%;"/>

For more information on figures, see here. Images generated through code is not covered here.

6.3 Static images using R

Quarto chunks can be used to control image display size using the argument out.width.

This image below is displayed at a size of 300 pixels.

```{r}
#| out-width: 300px
knitr::include_graphics("assets/image.webp")
```

This image below is displayed at a size of 75 pixels and a caption added.

```{r}
#| out-width: 75px
#| fig-cap: This is a caption
knitr::include_graphics("assets/image.webp")
```

This is a caption

This is a caption

For more information on figures, see here. For plots generated through R, see section further below.

7 Math expressions

Some examples of rendering equations.

$e^{i\pi} + 1 = 0$

\(e^{i\pi} + 1 = 0\)

$$\frac{E \times X^2 \prod I}{2+7} = 432$$

\[\frac{E \times X^2 \prod I}{2+7} = 432\]

$$\sum_{i=1}^n X_i$$

\[\sum_{i=1}^n X_i\]

$$\int_0^{2\pi} \sin x~dx$$

\[\int_0^{2\pi} \sin x~dx\]

$\left( \sum_{i=1}^{n}{i} \right)^2 = \left( \frac{n(n-1)}{2}\right)^2 = \frac{n^2(n-1)^2}{4}$

\(\left( \sum_{i=1}^{n}{i} \right)^2 = \left( \frac{n(n-1)}{2}\right)^2 = \frac{n^2(n-1)^2}{4}\)

$\begin{eqnarray} X & \sim & \mathrm{N}(0,1)\\ Y & \sim & \chi^2_{n-p}\\ R & \equiv & X/Y \sim t_{n-p} \end{eqnarray}$

\(\begin{eqnarray} X & \sim & \mathrm{N}(0,1)\\ Y & \sim & \chi^2_{n-p}\\ R & \equiv & X/Y \sim t_{n-p} \end{eqnarray}\)

$\begin{eqnarray} P(|X-\mu| > k) & = & P(|X-\mu|^2 > k^2)\\ & \leq & \frac{\mathbb{E}\left[|X-\mu|^2\right]}{k^2}\\ & \leq & \frac{\mathrm{Var}[X]}{k^2} \end{eqnarray}$

\(\begin{eqnarray} P(|X-\mu| > k) & = & P(|X-\mu|^2 > k^2)\\ & \leq & \frac{\mathbb{E}\left[|X-\mu|^2\right]}{k^2}\\ & \leq & \frac{\mathrm{Var}[X]}{k^2} \end{eqnarray}\)

8 Icons

8.1 Bootstrap icons

Bootstrap icons are directly available since quarto uses bootstrap for styling. Optionally, one could also use the quarto extension bsicons for more control.

<i class="bi bi-lightbulb-fill"></i>
<i class="bi bi-exclamation-circle-fill"></i>
<i class="bi bi-clipboard2-check-fill"></i>
<i class="bi bi-chat-fill"></i>
<i class="bi bi-laptop-fill"></i>
<i class="bi bi-cloud-fill"></i>
<i class="bi bi-github"></i>

8.2 Fontawesome

To use fontawesome icons as shortcodes, quarto extension fontawesome needs to be installed.

Icons can be placed using shortcodes.

{{< fa lightbulb >}}
{{< fa exclamation >}}
{{< fa clipboard-list >}}
{{< fa comments >}}
{{< fa desktop >}}
{{< fa cloud >}}
{{< fa check >}}
{{< fa times >}}
{{< fa skull >}}
{{< fa skull size=2x >}}
{{< fa brands github >}}

Icons can be displayed using the HTML <i> tag. Note that not all icons may work.

Here is a <i class='fa fa-calendar'></i> calendar and a <i class='fa fa-couch'></i> couch.

Here is a calendar and a couch.

There are many other quarto extensions for icons such as academicons, iconify and lordicons.

8.3 Icons in R

Icons can be placed programatically through R using the R package fontawesome.

`r fontawesome::fa('lightbulb')`

Optional arguments are height and fill.

`r fontawesome::fa('lightbulb',height='30px',fill='steelblue')`

For full list of icons check out FontAwesome.

9 Call-Outs

Call-Out blocks are explained here.

::: {.callout-note}
This is a call-out.
:::

::: {.callout-warning}
This is a call-out.
:::

::: {.callout-important}
This is a call-out.
:::

::: {.callout-tip}
This is a call-out.
:::

::: {.callout-caution}
This is a call-out.
:::

::: {.callout-tip collapse="true"}
## Call-out with collapse

This content is behind an accordion.
:::
Note

This is a call-out.

Warning

This is a call-out.

Important

This is a call-out.

Tip

This is a call-out.

Caution

This is a call-out.

This content is behind an accordion.

10 Alerts

::: {.alert .alert-primary}
**Note:** This is an alert!
:::
::: {.alert .alert-secondary}
**Note:** This is an alert!
:::
::: {.alert .alert-success}
**Note:** This is a success alert!
:::
::: {.alert .alert-danger}
**Note:** This is a danger alert!
:::
::: {.alert .alert-warning}
**Note:** This is a warning alert!
:::
::: {.alert .alert-info}
**Note:** This is an info alert!
:::

Note: This is an alert!

Note: This is an alert!

Note: This is a success alert!

Note: This is a danger alert!

Note: This is a warning alert!

Note: This is an info alert!

11 Layout

11.1 Span

[Content inside span]{style="background-color: gray"}

Content inside span

11.2 Div

::: {style="background-color: gray"}
Content inside div
:::

Content inside div

Divs can be nested like this:

:::: {.class}
::: {.class}
:::
::::

Both spans and divs support attributes in this specific order: identifiers, classes, and then key-value attributes.

[Content inside span]{#id .class key1="val1" key2="val2"}

11.3 Hidden div

::: {.hidden}
Hidden content
:::

11.4 Conditional content

::: {{.content-visible when-format="html"}}
Will only appear in HTML.
:::
::: {{.content-hidden when-format="html"}}
Will not appear in HTML.
:::

Conditional content is documented here.

11.5 Inner columns

Organisation of content into columns within the body container.

:::: {.columns}
::: {.column style="background-color: aliceblue"}
Content is left.
:::
::: {.column style="background-color:  #f5b7b1"}
Content is right.
:::
::::

Content in left column.

Content in right column.


This is an example of nested columns.

:::: {.columns}

::: {.column style="background-color: aliceblue"}
Content in left column.
:::

::: {.column}
Content in right column.

:::: {.columns}
::: {.column style="background-color: #d0ece7"}
Nested left.
:::
::: {.column style="background-color: #f2d7d5"}
Nested right.
:::
::::

:::

::::

Content in left column.

Content in right column.

Nested left.

Nested right.

11.6 Outer columns

Extending content outside the body container.

::: {.column-body style="background-color: lightgray; margin-bottom:0.5em;"}
.column-body
:::

::: {.column-body-outset style="background-color: lightgray; margin-bottom:0.5em;"}
.column-body-outset
:::

::: {.column-page-inset style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page-inset
:::

::: {.column-page style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page
:::

::: {.column-screen-inset style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen-inset
:::

::: {.column-screen style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen
:::

::: {.column-body-outset-right style="background-color: lightgray; margin-bottom:0.5em;"}
.column-body-outset-right
:::

::: {.column-page-inset-right style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page-inset-right
:::

::: {.column-page-right style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page-right
:::

::: {.column-screen-inset-right style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen-inset-right
:::

::: {.column-screen-right style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen-right
:::

::: {.column-body-outset-left style="background-color: lightgray; margin-bottom:0.5em;"}
.column-body-outset-left
:::

::: {.column-page-inset-left style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page-inset-left
:::

::: {.column-page-left style="background-color: lightgray; margin-bottom:0.5em;"}
.column-page-left
:::

::: {.column-screen-inset-left style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen-inset-left
:::

::: {.column-screen-left style="background-color: lightgray; margin-bottom:0.5em;"}
.column-screen-left
:::

::: {.column-margin style="background-color: lightgray; margin-bottom:0.5em;"}
.column-margin
:::

.column-body

.column-body-outset

.column-page-inset

.column-page

.column-screen-inset

.column-screen

.column-body-outset-right

.column-page-inset-right

.column-page-right

.column-screen-inset-right

.column-screen-right

.column-body-outset-left

.column-page-inset-left

.column-page-left

.column-screen-inset-left

.column-screen-left

.column-margin

11.7 Panel layout

::: {.panel-tabset}
#### Sub topic 1

This is some material for topic 1.

#### Sub topic 2

This is some material for topic 2.

:::

This is some material for topic 1.

This is some material for topic 2.

More layout settings are described here and here.

12 Tables

12.1 Manual

For simple cases, tables can be manually created in markdown.

|speed|dist|
|-----|----|
|4    |   2|
|4    |  10|
|7    |   4|
speed dist
4 2
4 10
7 4

Table caption and numbering can be added as such:

|speed|dist|
|-----|----|
|4    |   2|
|4    |  10|
|7    |   4|

: These are exciting results. {#tbl-mylabel}
Table 1: These are exciting results.
speed dist
4 2
4 10
7 4

More information about tables.

12.2 Margin table

A table placed in the margin.

::: {.column-margin}

| speed | dist |
|-------|------|
| 4     | 2    |
| 4     | 10   |
| 7     | 4    |

:::
speed dist
4 2
4 10
7 4

12.3 kable

Simple table using kable from R package knitr. This is the default output for quarto.

library(knitr)
head(iris)

12.3.1 Layout

```{r}
#| column: body-outset
#| label: tbl-dual-table
#| tbl-cap: "Example"
#| tbl-subcap: 
#|   - "Cars"
#|   - "Pressure"
#| layout-ncol: 2

kable(head(cars))
kable(head(pressure))
```
Table 2: Example
(a) Cars
speed dist
4 2
4 10
7 4
7 22
8 16
9 10
(b) Pressure
temperature pressure
0 0.0002
20 0.0012
40 0.0060
60 0.0300
80 0.0900
100 0.2700

12.3.2 Cross referencing

Images and tables can be automatically numbered by using label attribute. Image label must start with fig- and tables with tbl-. Tables and images can also be cross-referenced when using the label attribute. For example, the table above can be referenced like @tbl-dual-table which renders as Table 2.

12.3.3 Margin table

```{r}
#| fig-caption: This table is in the margin.
#| column: margin

head(cars)
```

12.4 gt

Tables using the gt package. A structured approach to creating tables using grammar of tables with extensive customization options.

library(gt)

iris %>%
    group_by(Species) %>%
    slice(1:4) %>%
    gt() %>%
    cols_label(
      Sepal.Length = "Sepal Length", Sepal.Width = "Sepal Width",
      Petal.Length = "Petal Length", Petal.Width = "Petal Width"
    ) %>%
    tab_source_note(
        source_note = md("Source: Iris data. Anderson, 1936; Fisher, 1936)")
    )
Sepal Length Sepal Width Petal Length Petal Width
setosa
5.1 3.5 1.4 0.2
4.9 3.0 1.4 0.2
4.7 3.2 1.3 0.2
4.6 3.1 1.5 0.2
versicolor
7.0 3.2 4.7 1.4
6.4 3.2 4.5 1.5
6.9 3.1 4.9 1.5
5.5 2.3 4.0 1.3
virginica
6.3 3.3 6.0 2.5
5.8 2.7 5.1 1.9
7.1 3.0 5.9 2.1
6.3 2.9 5.6 1.8
Source: Iris data. Anderson, 1936; Fisher, 1936)

12.5 htmlTable

Markdown tables can be enhanced using the R package htmlTable.

library(htmlTable)

iris1 <- iris[c(1:4,51:53,105:108),]
htmlTable(iris1, rgroup=unique(iris1$Species), n.rgroup=rle(as.character(iris1$Species))$lengths)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
setosa
  1 5.1 3.5 1.4 0.2 setosa
  2 4.9 3 1.4 0.2 setosa
  3 4.7 3.2 1.3 0.2 setosa
  4 4.6 3.1 1.5 0.2 setosa
versicolor
  51 7 3.2 4.7 1.4 versicolor
  52 6.4 3.2 4.5 1.5 versicolor
  53 6.9 3.1 4.9 1.5 versicolor
virginica
  105 6.5 3 5.8 2.2 virginica
  106 7.6 3 6.6 2.1 virginica
  107 4.9 2.5 4.5 1.7 virginica
  108 7.3 2.9 6.3 1.8 virginica

12.6 kableExtra

More advanced table using kableExtra and formattable.

library(kableExtra)

iris[c(1:4,51:53,105:108),] %>%
  mutate(Sepal.Length=color_bar("lightsteelblue")(Sepal.Length)) %>%
  mutate(Sepal.Width=color_tile("white","orange")(Sepal.Width)) %>%
  mutate(Species=cell_spec(Species,"html",color="white",bold=T,
    background=c("#8dd3c7","#fb8072","#bebada")[factor(.$Species)])) %>%
  kable("html",escape=F) %>%
  kable_styling(bootstrap_options=c("striped","hover","responsive"),
                full_width=F,position="left") %>%
  column_spec(5,width="3cm")
Table using kableextra.
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
51 7.0 3.2 4.7 1.4 versicolor
52 6.4 3.2 4.5 1.5 versicolor
53 6.9 3.1 4.9 1.5 versicolor
105 6.5 3.0 5.8 2.2 virginica
106 7.6 3.0 6.6 2.1 virginica
107 4.9 2.5 4.5 1.7 virginica
108 7.3 2.9 6.3 1.8 virginica

12.7 DT

Interactive table using R package DT.

library(DT)

iris %>%
  slice(1:15) %>%
  datatable(options=list(pageLength=7))

12.8 reactable

Advanced interactive tables with reactable.

library(reactable)

reactable(iris[sample(1:150,10),],
  columns = list(
    Sepal.Length = colDef(name = "Sepal Length"),
    Sepal.Width = colDef(name = "Sepal Width"),
    Petal.Width = colDef(name = "Petal Width"),
    Petal.Width = colDef(name = "Petal Width")
  ),
  striped = TRUE,
  highlight = TRUE,
  filterable = TRUE
)

reactable creation can be simplified as well as enhanced by using reactablefmtr.

13 Static plots

13.1 Base plot

  • Plots using base R are widely used and may be good enough for most situations.
  • But they lack a consistent coding framework.
{
  plot(x=iris$Sepal.Length,y=iris$Sepal.Width,
      col=c("coral","steelblue","forestgreen")[iris$Species],
      xlab="Sepal Length",ylab="Sepal Width",pch=19)

  legend(x=7,y=4.47,legend=c("setosa","versicolor","virginica"),
        col=c("coral","steelblue","forestgreen"),pch=19)
}
Figure 2: Static plot using base plot.

13.1.1 Multiple plots

```{r}
#| column: screen-inset-shaded
#| layout-nrow: 1
#| fig-cap:
#|   - "Scatterplot of speed vs distance"
#|   - "Pairwise scatterplot of all variables"
#|   - "Scatterplot of temperature vs pressure"

plot(cars)
plot(iris)
plot(pressure)
```

Scatterplot of speed vs distance

Scatterplot of speed vs distance

Pairwise scatterplot of all variables

Pairwise scatterplot of all variables

Scatterplot of temperature vs pressure

Scatterplot of temperature vs pressure

13.1.2 Margin plot

```{{r}}
#| column: margin

plot(cars)
```
plot(cars)

13.2 ggplot2

R package ggplot2 is one of the most versatile and complete plotting solutions.

library(ggplot2)

iris %>%
  ggplot(aes(x=Sepal.Length,y=Sepal.Width,col=Species))+
  geom_point(size=2)+
  labs(x="Sepal Length",y="Sepal Width")+
  theme_report()

Static plot using ggplot2.

Static plot using ggplot2.

14 Interactive plots

14.1 highcharter

R package highcharter is a wrapper around javascript library highcharts.

library(highcharter)

h <- iris %>%
  hchart(.,"scatter",hcaes(x="Sepal.Length",y="Sepal.Width",group="Species")) %>%
  hc_xAxis(title=list(text="Sepal Length"),crosshair=TRUE) %>%
  hc_yAxis(title=list(text="Sepal Width"),crosshair=TRUE) %>%
  hc_chart(zoomType="xy",inverted=FALSE) %>%
  hc_legend(verticalAlign="top",align="right") %>%
  hc_size(height=400)

htmltools::tagList(list(h))

Interactive scatterplot using highcharter.

14.2 plotly

R package plotly provides R binding around javascript plotting library plotly.

library(plotly)

p <- iris %>%
  plot_ly(x=~Sepal.Length,y=~Sepal.Width,color=~Species,width=500,height=400) %>%
  add_markers()
p

Interactive scatterplot using plotly.

14.3 ggplotly

plotly also has a function called ggplotly which converts a static ggplot2 object into an interactive plot.

library(plotly)

p <- iris %>%
  ggplot(aes(x=Sepal.Length,y=Sepal.Width,col=Species))+
  geom_point()+
  labs(x="Sepal Length",y="Sepal Width")+
  theme_bw(base_size=12)

ggplotly(p,width=500,height=400)

Interactive scatterplot using ggplotly.

14.4 ggiraph

ggiraph is also an R package that can be used to convert a static ggplot2 object into an interactive plot.

library(ggiraph)

p <- ggplot(iris,aes(x=Sepal.Length,y=Petal.Length,colour=Species))+
      geom_point_interactive(aes(tooltip=paste0("<b>Petal Length:</b> ",Petal.Length,"\n<b>Sepal Length: </b>",Sepal.Length,"\n<b>Species: </b>",Species)),size=2)+
  theme_bw()

tooltip_css <- "background-color:#e7eef3;font-family:Roboto;padding:10px;border-style:solid;border-width:2px;border-color:#125687;border-radius:5px;"

girafe(code=print(p),
  options=list(
    opts_hover(css="cursor:pointer;stroke:black;fill-opacity:0.3"),
    opts_zoom(max=5),
    opts_tooltip(css=tooltip_css,opacity=0.9)
  )
)

Interactive scatterplot using ggiraph.

14.5 dygraphs

R package dygraphs provides R bindings for javascript library dygraphs for time series data.

library(dygraphs)

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths,main="Deaths from Lung Disease (UK)") %>%
  dyOptions(colors=c("#66C2A5","#FC8D62","#8DA0CB"))

Interactive time series plot using dygraph.

14.6 Network graph

R package networkD3 allows the use of interactive network graphs from the D3.js javascript library.

library(networkD3)

data(MisLinks,MisNodes)
forceNetwork(Links=MisLinks,Nodes=MisNodes,Source="source",
             Target="target",Value="value",NodeID="name",
             Group="group",opacity=0.4)

Interactive network plot.

14.7 leaflet

R package leaflet provides R bindings for javascript mapping library; leafletjs.

library(leaflet)

leaflet(height=500,width=700) %>%
  addTiles(urlTemplate='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png') %>%
  #addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
  addMarkers(lat=57.639327,lng=18.288534,popup="RaukR") %>%
  setView(lat=57.639327,lng=18.288534,zoom=15)

Interactive map using leaflet.

14.8 crosstalk

R package crosstalk allows crosstalk enabled plotting libraries to be linked. Through the shared ‘key’ variable, data points can be manipulated simultaneously on two independent plots.

library(crosstalk)

shared_quakes <- SharedData$new(quakes[sample(nrow(quakes), 100),])
lf <- leaflet(shared_quakes,height=300) %>%
        addTiles(urlTemplate='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png') %>%
        addMarkers()
py <- plot_ly(shared_quakes,x=~depth,y=~mag,size=~stations,height=300) %>%
        add_markers()

htmltools::div(lf,py)

Linking independent plots using crosstalk.

15 ObservableJS

Quarto supports ObservableJS for interactive visualisations in the browser.

Pass data from R to OJS

irism <- iris
colnames(irism) <- gsub("[.]","_",tolower(colnames(irism)))
ojs_define(ojsd = irism)
ojsdata = transpose(ojsd)

Display as a table

viewof filtered_table = Inputs.table(ojsdata)

Define inputs

viewof x = Inputs.select(Object.keys(ojsdata[0]), {value: "sepal_length", multiple: false, label: "X axis"})
viewof y = Inputs.select(Object.keys(ojsdata[0]), {value: "sepal_width", multiple: false, label: "Y axis"})

Display plot

Plot.plot({
  marks: [
    Plot.dot(ojsdata, {
      x: x,
      y: y,
      fill: "species",
      title: (d) =>
        `${d.species} \n Petal length: ${d.petal_length} \n Sepal length: ${d.sepal_length}`
    })
  ],
  grid: true
})

ObservableJS in quarto documentation.

16 General tips

  • Use level 2 heading as the highest level
## Section A
  • Add custom css under YAML if needed css: "my-theme.css"
  • Check out the Quarto website

17 Session

Click here
sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] knitr_1.50        fontawesome_0.5.3 crosstalk_1.2.1   leaflet_2.2.2    
 [5] networkD3_0.4.1   dygraphs_1.1.1.6  ggiraph_0.8.13    plotly_4.10.4    
 [9] highcharter_0.9.4 ggplot2_3.5.2     reactable_0.4.4   DT_0.33          
[13] gt_1.0.0          formattable_0.2.1 kableExtra_1.4.0  htmlTable_2.4.3  
[17] stringr_1.5.1     tidyr_1.3.1       dplyr_1.1.4      

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1   viridisLite_0.4.2  farver_2.1.2       fastmap_1.2.0     
 [5] lazyeval_0.2.2     promises_1.3.2     digest_0.6.37      mime_0.13         
 [9] timechange_0.3.0   lifecycle_1.0.4    magrittr_2.0.3     compiler_4.4.3    
[13] rlang_1.1.6        sass_0.4.10        tools_4.4.3        igraph_2.1.4      
[17] yaml_2.3.10        data.table_1.17.0  labeling_0.4.3     htmlwidgets_1.6.4 
[21] curl_6.2.2         xml2_1.3.8         TTR_0.24.4         RColorBrewer_1.1-3
[25] withr_3.0.2        purrr_1.0.4        grid_4.4.3         xts_0.14.1        
[29] xtable_1.8-4       colorspace_2.1-1   data.tree_1.1.0    scales_1.3.0      
[33] cli_3.6.5          rmarkdown_2.29     generics_0.1.3     rlist_0.4.6.2     
[37] rstudioapi_0.17.1  httr_1.4.7         commonmark_1.9.5   cachem_1.1.0      
[41] assertthat_0.2.1   base64enc_0.1-3    vctrs_0.6.5        jsonlite_2.0.0    
[45] litedown_0.7       systemfonts_1.2.2  jquerylib_0.1.4    quantmod_0.4.27   
[49] glue_1.8.0         reactR_0.6.1       lubridate_1.9.4    stringi_1.8.7     
[53] gtable_0.3.6       later_1.4.2        munsell_0.5.1      tibble_3.2.1      
[57] pillar_1.10.2      htmltools_0.5.8.1  R6_2.6.1           evaluate_1.0.3    
[61] shiny_1.10.0       lattice_0.22-7     markdown_2.0       backports_1.5.0   
[65] broom_1.0.8        httpuv_1.6.16      bslib_0.9.0        Rcpp_1.0.14       
[69] uuid_1.2-1         svglite_2.1.3      checkmate_2.3.2    xfun_0.52         
[73] zoo_1.8-14         pkgconfig_2.0.3   

Footnotes

  1. That reference refers to this footnote.↩︎