Examples

Data

sat.act data

Load the {psych} package and use the sat.act data:

library(psych)
head(sat.act)
      gender education age ACT SATV SATQ
29442      2         3  19  24  500  500
29457      2         3  23  35  600  500
29498      2         3  20  21  480  470
29503      1         4  27  26  550  520
29504      1         2  33  31  600  550
29518      1         5  26  28  640  640

From the data description (see ?psych::sat.act):

Self reported scores on the SAT Verbal, SAT Quantitative and ACT were collected as part of the Synthetic Aperture Personality Assessment (SAPA) web based personality assessment project. Age, gender, and education are also reported. The data from 700 subjects are included here as a demonstration set for correlation and analysis.

Examples

This section includes code for the examples shown. These may differ slightly from the examples shown in the live demonstration.

Example 1: Your first Quarto document

See example
example1.qmd
---
title: "My Document"
author: "Nicola Rennie"
format: html
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

```{r}
1 + 1
```

You can add options to executable code like this 

```{r}
#| echo: false
2 * 2
```

The `echo: false` option disables the printing of code (only output is displayed).

Example 2: Document content

You can download the image file here (or find your own!): lemurs.jpg

See example
example2.qmd
---
title: "My Document"
author: "Nicola Rennie"
format: html
---

# Level 1 Heading

## Level 2 Heading

We can write lists in markdown. For example, the top 3 best animals:

-   lemurs
-   dogs
-   hedgehogs

Numbered lists are made easier in markdown:

1.  lemurs
2.  dogs
3.  hedgehogs

You can make text *italic* or **bold**.

We can add images:

![](lemurs.jpg){fig-align="center" width="50%"}

and tables:

| Animal   | Score |
|----------|-------|
| Lemur    | 10    |
| Dog      | 9     |
| Hedgehog | 8     |

: Rating of animals

Example 3: Code blocks

See example
example3.qmd
---
title: "My Document"
author: "Nicola Rennie"
format: html
execute: 
  eval: true
  echo: false
---

# Level 1 Heading

## Level 2 Heading

We can write lists in markdown. For example, the top 3 best animals:

-   lemurs
-   dogs
-   hedgehogs

Numbered lists are made easier in markdown:

1.  lemurs
2.  dogs
3.  hedgehogs

You can make text *italic* or **bold**.

We can add images:

![](lemurs.jpg){fig-align="center" width="50%"}

and tables:

| Animal   | Score |
|----------|-------|
| Lemur    | 10    |
| Dog      | 9     |
| Hedgehog | 8     |

: Rating of animals


## Analysis

```{r}
#| label: load-data
library(psych)
data(bfi)
```

Adding a plot

```{r}
#| label: age-hist
#| fig-align: center
#| fig-width: 6
#| fig-height: 6
#| fig-cap: "A histogram of participant age"
hist(bfi$age, xlab = "Age", main = "")
```

Prepare data for a table:

```{r}
#| label: table-prep
data("sat.act")
sat_summary <- aggregate(
  cbind(SATV, SATQ) ~ education,
  FUN = mean,
  data = sat.act
)
```

Make a table:

```{r}
#| tbl-cap: "Mean scores by education level"
library(tinytable)
tt(sat_summary)
```

Example 4: Document referencing

See example
example4.qmd
---
title: "My Document"
author: "Nicola Rennie"
bibliography: references.bib
format: html
number-sections: true
execute: 
  eval: true
  echo: false
---

# Level 1 Heading

## Level 2 Heading

We can write lists in markdown. For example, the top 3 best animals:

-   lemurs
-   dogs
-   hedgehogs

Numbered lists are made easier in markdown:

1.  lemurs
2.  dogs
3.  hedgehogs

You can make text *italic* or **bold**.

We can add images such as @fig-lemur

![](lemurs.jpg){#fig-lemur fig-align="center" width="50%"}

and tables:

| Animal   | Score |
|----------|-------|
| Lemur    | 10    |
| Dog      | 9     |
| Hedgehog | 8     |

: Rating of animals


## Analysis {#sec-analysis}

In @sec-analysis we explore the data.

```{r}
#| label: load-data
library(psych)
data(bfi)
```

Adding a plot such as a histogram in @fig-age-hist:

```{r}
#| label: fig-age-hist
#| fig-align: center
#| fig-width: 6
#| fig-height: 6
#| fig-cap: "A histogram of participant age"
hist(bfi$age, xlab = "Age", main = "")
```

Prepare data for a table:

```{r}
#| label: table-prep
data("sat.act")
sat_summary <- aggregate(
  cbind(SATV, SATQ) ~ education,
  FUN = mean,
  data = sat.act
)
```

Make a table using the {tinytable} package [@tinytable]:

```{r}
#| tbl-cap: "Mean scores by education level"
library(tinytable)
tt(sat_summary)
```
references.bib
@Manual{tinytable,
  title = {tinytable: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown',
'Word', 'PNG', 'PDF', and 'Typst' Formats},
  author = {Vincent Arel-Bundock},
  year = {2024},
  note = {R package version 0.2.1},
  url = {https://CRAN.R-project.org/package=tinytable},
}

Example 5: Formatting documents

See example
example5.qmd
---
title: "My Document"
format: tandf-pdf
bibliography: references.bib
execute: 
  eval: true
  echo: false
---

# Level 1 Heading

## Level 2 Heading

We can write lists in markdown. For example, the top 3 best animals:

-   lemurs
-   dogs
-   hedgehogs

Numbered lists are made easier in markdown:

1.  lemurs
2.  dogs
3.  hedgehogs

You can make text *italic* or **bold**.

We can add images such as @fig-lemur

![](lemurs.jpg){#fig-lemur fig-align="center" width="50%"}

and tables:

| Animal   | Score |
|----------|-------|
| Lemur    | 10    |
| Dog      | 9     |
| Hedgehog | 8     |

: Rating of animals


## Analysis {#sec-analysis}

In @sec-analysis we explore the data.

```{r}
#| label: load-data
library(psych)
data(bfi)
```

Adding a plot such as a histogram in @fig-age-hist:

```{r}
#| label: fig-age-hist
#| fig-align: center
#| fig-width: 6
#| fig-height: 6
#| fig-cap: "A histogram of participant age"
hist(bfi$age, xlab = "Age", main = "")
```

Prepare data for a table:

```{r}
#| label: table-prep
data("sat.act")
sat_summary <- aggregate(
  cbind(SATV, SATQ) ~ education,
  FUN = mean,
  data = sat.act
)
```

Make a table using the {tinytable} package [@tinytable]:

```{r}
#| tbl-cap: "Mean scores by education level"
library(tinytable)
tt(sat_summary)
```
references.bib
@Manual{tinytable,
  title = {tinytable: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown',
'Word', 'PNG', 'PDF', and 'Typst' Formats},
  author = {Vincent Arel-Bundock},
  year = {2024},
  note = {R package version 0.2.1},
  url = {https://CRAN.R-project.org/package=tinytable},
}

In the same folder as example5.qmd there should be the lemurs.jpg image, and another folder called _extensions/mikemahoney218/tandf. When you render the document, you should also see orcidlink.sty and interact.csl files.