Quarto Report

In this practical, you will recreate this html report.

0 - Preliminaries

  1. Go to the File - New File menu and select the file type Quarto Document, enter the title Do the rich get richer in Basel? and your name, leave the file type as HTML and then hit Create.

  2. Click the Render button and observe whether the template content currently included in the file is correctly rendered and displayed in the Viewer Pane. When you render for the first time, you will be asked to choose a file name. Call the document basel_report

  3. Clear everything in the document except for the YAML header.

  4. Add an initial R chunk accessing the Menu with Code - Insert Chunk.

  5. Within the chunk add #| include: false in the first line to suppress messages, e.g., from the tidyverse. Load the tidyverse and patchwork packages. Read in the taxation.csv data as a new object called basel. Note that when running the Quarto file it will use its own location as the working directory. Consequently, use 1_data/taxation.csv as the file path.

  6. Render the document and check whether the data and packages are loaded correctly, i.e., you don’t see an error message.

  7. Include echo: false in your YAML header to remove code display for all chunks in the document. Be careful to follow the indentation as shown below!

format: 
  html
execute:
  echo: false

2 - Intro

  1. Copy the following text below the initial chunk.
Inequalities in income and wealth are a growing social issue FOOTNOTE. This analysis seeks to quantify inequality in Basel, Switzerland, by analyzing the widening of wealth and income gaps between the city's quarters.   
  1. Next replace the text FOOTNOTE with the actual footnote ^[See https://www.un.org/en/un75/inequality-bridging-divide.].

  2. Render the document (i.e., hit the Render button) and observe whether the new contents are accurately displayed.

3 - Data

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

  2. Below the header add the following text.

The data provided by LINK contains information on the wealth and income of the inhabitants of the INLINE quarters of Basel based on tax-return documents. 
  1. Replace the text LINK with [Open Data Basel](https://www.opendata.bs.ch/) to link to the Basel Open Data webpage.

  2. Replace the text INLINE with a piece of inline R code determining the number of quarters in Basel, namely with ‘r length(unique(basel))’. Make sure to put accents before and after the inline code (not apostrophes as used here).

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

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

5 - Conclusion

  1. Create a header at the third level (###) with the title Limitations and outlook.

  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.

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

7 - Further tasks

  1. After the figure add a new paragraph entitled: Top and bottom quarters.

  2. Within a new R-chunk produce a vector high with the five quarters with the highest income, and a vector low with the five quarters with the lowest income.

  3. Include the names of these ten quarters in the new paragraph as inline code.