Quarto Report
In this practical, you will recreate this html report.
0 - Preliminaries
Go to the File - New File menu and select the file type
Quarto Document , enter the titleDo the rich get richer in Basel?and your name, leave the file type as HTML and then hitCreate .Click the
Renderbutton 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 documentbasel_reportClear everything in the document except for the YAML header.
Add an initial R chunk accessing the Menu with
Code - Insert Chunk.Within the chunk add
#| include: falsein the first line to suppress messages, e.g., from the tidyverse. Load thetidyverseandpatchworkpackages. Read in thetaxation.csvdata as a new object calledbasel. Note that when running the Quarto file it will use its own location as the working directory. Consequently, use1_data/taxation.csvas the file path.Render the document and check whether the data and packages are loaded correctly, i.e., you don’t see an error message.
Include
echo: falsein 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: false2 - Intro
- 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. Next replace the text
FOOTNOTEwith the actual footnote^[See https://www.un.org/en/un75/inequality-bridging-divide.].Render the document (i.e., hit the
Renderbutton) and observe whether the new contents are accurately displayed.
3 - Data
Create a header at the third level (
###) with the titleIncome and wealth.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. Replace the text
LINKwith[Open Data Basel](https://www.opendata.bs.ch/)to link to the Basel Open Data webpage.Replace the text
INLINEwith 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).Render the document and observe whether the new contents are displayed.
4 - 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.
5 - Conclusion
Create a header at the third level (
###) with the titleLimitations and outlook.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.
6 - 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.
7 - Further tasks
After the figure add a new paragraph entitled:
Top and bottom quarters.Within a new R-chunk produce a vector
highwith the five quarters with the highest income, and a vectorlowwith the five quarters with the lowest income.Include the names of these ten quarters in the new paragraph as inline code.