R Markdown amidst Madison parks

- City of Madison data
- Code

This document is part of teaching materials created for the workshop ‘Open data and reproducibility v2.1: R Markdown, dashboards and Binder’, delivered at the CarpentryCon 2020 conference. The purpose of this specific document is to practise R Markdown, including basic features such as Markdown markup and code chunks, along with more special features such as cross-references for figures, tables, code chunks, etc. The code is on GitHub.

Since this conference was originally going to take place in Madison, let’s look at some open data from the City of Madison.

Park types

[Placeholder text] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Figure 1 shows the number of parks within each type.

# Showing the code because echo = TRUE 
dat = read.csv('https://opendata.arcgis.com/datasets/9e00ff81868e49b7ba65d4e628b9e14f_6.csv')

dat = 
  dat %>%
  group_by(Type) %>%
  mutate(parks_number = n())

ggplotly(
  ggplot(dat, aes(x=reorder(Type, parks_number), y=parks_number,
                  text = paste('Number of parks =', parks_number))) + 
    theme(axis.title.y=element_blank()) + stat_identity(geom='bar') + 
    labs(x='Type', y='Number of parks') + coord_flip(), 
  tooltip = 'text'
)

Figure 1: Number of parks within each type.

Twenty largest parks

[Placeholder text] Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Table 1 shows the twenty largest parks types, along with their type and acreage. The code doesn’t show below because echo = FALSE.

Table 1: The twenty largest parks in Madison.
NameTypeAcreage
Cherokee Marsh - North UnitCONSERVATION946.58
Cherokee Marsh - South Unit (School Road Unit)CONSERVATION261.27
Elver ParkCOMMUNITY250.82
Northeast ParkCOMMUNITY237.76
Warner ParkCOMMUNITY213.49
Door Creek ParkCOMMUNITY159.97
Cherokee Marsh - Mendota UnitCONSERVATION122.08
Owen Conservation ParkCONSERVATION96.79
Reindahl (Amund) ParkCOMMUNITY90.74
Olbrich ParkCOMMUNITY90.01
Yahara Hills Park (West)COMMUNITY82.20
Sycamore ParkCOMMUNITY71.42
Turville Point Conservation ParkCONSERVATION64.28
Edna Taylor Conservation ParkCONSERVATION60.27
Quann ParkCOMMUNITY55.43
Demetral ParkCOMMUNITY49.18
Prairie Ridge Conservation ParkCONSERVATION48.76
Olin ParkCOMMUNITY47.12
Hiestand ParkCOMMUNITY46.27
Vilas (Henry) ParkCOMMUNITY45.67

We could decide to display the code for the table at this point (or any other), which can be done using the parameters ref.label = 'largest-parks', echo = TRUE, eval = FALSE in the chunk options (Xie, Dervieux, & Riederer, 2020).

dat %>%
  summarize(Name = Park_Name, Type, Acreage) %>%
  arrange(-Acreage, Name, Type) %>%
  select(Name, Type, Acreage) %>%
  head(20) %>%
  kable(caption = 'The twenty largest parks in Madison.')
comments powered by Disqus