Quarto Report 2

In this practical, you will update and adapt your report, so that is ultimately will look like this.

0 - Preliminaries

  1. Open the basel_report.qmd file you created in the last session.

1 - Add a Table of Contents

  1. Add the following code to show a Table of Contents and change the Title to Contents. The self-contained option makes sure that all the relevant information is written directly into the html file.
format: 
  html: 
    self-contained: true
    toc: true
    toc-title: Contents
  1. Move Table of Contents to the left
toc-location: left

2 Add the Open Data Basel-Stadt logo to the right margin

  1. Add the Open Data logo from the city of Basel with the following code:
::: {.column-margin}
![](https://avatars.githubusercontent.com/u/46960540?s=800&v=4)
:::
  1. Directly after the link information of the logo add the following code and adjust the width of the logo to an appropriate size.
![](https://avatars.githubusercontent.com/u/46960540?s=800&v=4){width="X"}

3 - Add a diagram to describe the data structure

  1. 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

  1. Add the knitr package to the initial chunk in your document with:
library(knitr)
  1. Add a new section at the end of your file with a third level heading Appendix.

  2. 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)
  1. 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")
  1. Render the document and observe whether the new contents are accurately displayed.

6 - Cross references

  1. Add a label to the figure

  2. Cross-reference the figure from wihtin the text ..

  3. Add a lable to the diagram and the table (#tbl-XX) in the same way.

  4. In the text, find appropriate positions to reference each of the three objects (figure, diagram, table) you just labelled.

  5. Render the document and observe whether the new contents are displayed.

7 - Visualization

  1. Create a header at the third level (###) with the title Quantifying inequality.

  2. 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.
  1. Next, move the cursor below the text you just added and add a new R chunk (Code - Insert Chunk).

  2. 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"))
  
  1. Render the document and observe that there it now includes a visualization.

  2. Add the following to the chunk settings: |# fig-asp: .7 to improve the use more of the width of the document, and |# out-width: 100%.

  3. Render the document and observe that the aspect ratio of the plot has changed.

8 - Conclusion

  1. Create a header at the third level (###) with the title Income and wealth.

  2. 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.
  1. Render the document and observe that all of the report’s contents are now included.

9- Theme

  1. Finally, change the YAML header so that a different styling theme (flatly) is used.
format: 
  html
execute:
  echo: false
theme: flatly
  1. Render the document and observe that the report is complete.

Further Tasks

  1. Produce a .reveal-js presentation with at least 6 slides using the data in inequality from Basel.