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.
Name Type Acreage
Cherokee Marsh - North Unit CONSERVATION 946.58
Cherokee Marsh - South Unit (School Road Unit) CONSERVATION 261.27
Elver Park COMMUNITY 250.82
Northeast Park COMMUNITY 237.76
Warner Park COMMUNITY 213.49
Door Creek Park COMMUNITY 159.97
Cherokee Marsh - Mendota Unit CONSERVATION 122.08
Owen Conservation Park CONSERVATION 96.79
Reindahl (Amund) Park COMMUNITY 90.74
Olbrich Park COMMUNITY 90.01
Yahara Hills Park (West) COMMUNITY 82.20
Sycamore Park COMMUNITY 71.42
Turville Point Conservation Park CONSERVATION 64.28
Edna Taylor Conservation Park CONSERVATION 60.27
Quann Park COMMUNITY 55.43
Demetral Park COMMUNITY 49.18
Prairie Ridge Conservation Park CONSERVATION 48.76
Olin Park COMMUNITY 47.12
Hiestand Park COMMUNITY 46.27
Vilas (Henry) Park COMMUNITY 45.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