Quarto Report 2
In this practical, you will update and adapt your report, so that is ultimately will look like this.
0 - Preliminaries
- Open the
basel_report.qmdfile you created in the last session.
1 - Add a Table of Contents
- Add the following code to show a Table of Contents and change the Title to
Contents. Theself-containedoption makes sure that all the relevant information is written directly into the html file.
format:
html:
self-contained: true
toc: true
toc-title: Contents- Move Table of Contents to the left
toc-location: left2 Add the Open Data Basel-Stadt logo to the right margin
- Add the Open Data logo from the city of Basel with the following code:
::: {.column-margin}

:::- Directly after the link information of the logo add the following code and adjust the width of the logo to an appropriate size.
{width="X"}3 - Add a diagram to describe the data structure
- Copy the following Mermaid code into a new chunk.
```{mermaid}
%%| echo: false
%%| label: fig-gini
%%| fig-cap: "Schematic overview of the data"
flowchart LR
A{Basel} --> B[Altstadt Grossbasel]
A{Basel} --> C[...]
A{Basel} --> D[Wettstein]
B --> E[2001]
B --> F[...]
B --> G[2017]
E --> H[Number of tax returns]
E --> I[Mean income]
E --> J[Mean Wealth]
```5 - Add a table in the Appendix showing data for Altstadt Grossbasel
- Add the knitr package to the initial chunk in your document with:
library(knitr)Add a new section at the end of your file with a third level heading
Appendix.Add the following code in a new R-chunk.
#| label: tbl-grossbasel
#| tbl-cap: "Data excerpt for Altstadt Grossbasel"
AltGross <-
basel %>%
filter(quarter == 'Altstadt Grossbasel') %>%
select(quarter, year, N, income_mean, wealth_mean)- Add the following code to print your table using the
kable()function.
kable(AltGross,
col.names = c("Quarter", "Year", "N","Mean income", "Mean Wealth"),
align = "ccccc")- Render the document and observe whether the new contents are accurately displayed.
6 - Cross references
Add a label to the figure
Cross-reference the figure from wihtin the text ..
Add a lable to the diagram and the table (#tbl-XX) in the same way.
In the text, find appropriate positions to reference each of the three objects (figure, diagram, table) you just labelled.
Render the document and observe whether the new contents are displayed.
7 - Visualization
Create a header at the third level (
###) with the titleQuantifying inequality.Below the header, add the following text:
The figure below shows the development of income (panel A) and wealth (panel B) in Basel's quarters in the years 2001 to 2017. It can be observed that the incomes in poorer quarters in 2001 declined with time, whereas those of richer quarters rose. Similarly, wealth in poorer quarters rose less strongly than wealth in quarters that started out wealthier. These results suggest a widening of income and wealth inequality in Basel.Next, move the cursor below the text you just added and add a new R chunk (
Code - Insert Chunk).Now, copy the following code into the newly-created, empty chunk.
# create quarter factor
basel <- basel %>%
arrange(year, income_mean) %>%
mutate(quarter = as_factor(quarter))
# create income plot
plot_income <- basel %>%
ggplot(aes(x = year, y = income_mean, col = quarter)) +
labs(x = "Year", y = "Income")
# create income plot
plot_wealth <- basel %>%
ggplot(aes(x = year, y = wealth_median, col = quarter)) +
labs(x = "Year", y = "Wealth")
# create joint plot
plot_income + plot_wealth +
plot_layout(guides = "collect") +
plot_annotation(title = "Inequality in Basel",
subtitle = "Income and wealth development from 2001 to 2017",
caption = "Source: Open Data Basel",
tag_levels = "A") &
geom_point() &
geom_line() &
scale_color_viridis_d() &
theme_minimal() &
theme(legend.position = "bottom",
legend.title = element_blank(),
legend.key.height = unit(.01,"in"))
Render the document and observe that there it now includes a visualization.
Add the following to the chunk settings:
|# fig-asp: .7to improve the use more of the width of the document, and|# out-width: 100%.Render the document and observe that the aspect ratio of the plot has changed.
8 - Conclusion
Create a header at the third level (
###) with the titleIncome and wealth.Below the header, add the following text:
The presented analysis of income and wealth inequalities based on Basel's quarters comes with several limitations. Most importantly, the analysis does not account for mobility, implying that some of the temporal differences could driven by changes in the quarters' inhabitants. More detailed analyses which track inhabited across time will be needed to demonstrate conclusively a widening of inequality in Basel.- Render the document and observe that all of the report’s contents are now included.
9- Theme
- Finally, change the YAML header so that a different styling theme (
flatly) is used.
format:
html
execute:
echo: false
theme: flatly- Render the document and observe that the report is complete.
Further Tasks
- Produce a .reveal-js presentation with at least 6 slides using the data in inequality from Basel.