This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Belfast trees" | |
author: "Ciarán" | |
date: '2018-03-07' | |
slug: belfast-trees | |
tags: ["trees", "belfast"] | |
categories: ["rstats"] | |
--- | |
```{r setup, echo=FALSE, include=FALSE} | |
knitr::opts_chunk$set(cache = TRUE, | |
echo = FALSE) | |
library(tidyverse) | |
library(curl) | |
library(kableExtra) # for tidy tables | |
library(leaflet) # for maps | |
#treesurl <- "http://www.belfastcity.gov.uk/nmsruntime/saveasdialog.aspx?lID=14543&sID=2430" | |
#trees <- read_csv(url(treesurl)) | |
trees <- read_csv("../../TressData.csv") | |
``` | |
I was poking around the [Open Data NI](https://www.opendatani.gov.uk) website this evening when I stumbled across the Belfast trees [dataset](https://www.opendatani.gov.uk/dataset/belfast-trees/resource/b501ba21-e26d-46d6-b854-26a95db78dd9). The dataset provides a location for each of `r prettyNum(nrow(trees), big.mark = ",")` trees in the city (as of November 2015) plus its species, health and diameter. There's a nice tree map [here](http://data.nicva.org/dataset/belfast-trees) but I thought I might practice my R mapping skills for a bit of fun. Where are Belfast's most unusual trees? | |
```{r sort_by_species, message=FALSE, warning=FALSE, include=FALSE, paged.print=FALSE} | |
trees_species <- trees %>% | |
group_by(SPECIESTYPE) %>% | |
summarise(Trees = n()) %>% | |
arrange(desc(Trees)) | |
``` | |
First off, there are `r nrow(trees_species)` different species of tree on the list, of which the six most frequent are: | |
```{r frequent_species, echo=FALSE, message=FALSE, warning=FALSE} | |
frequent_trees <- trees_species %>% | |
slice(1:6) %>% | |
rename(Species = SPECIESTYPE) | |
knitr::kable(frequent_trees, format = "html", align = "l") %>% | |
kable_styling(full_width = FALSE, bootstrap_options = "striped") | |
``` | |
The bottom of the list is just as interesting. Our six least common trees are: | |
```{r uncommon_species, echo=FALSE, message=FALSE, warning=FALSE} | |
uncommon_trees <- tail(trees_species) %>% # get the least common trees | |
rename(Species = SPECIESTYPE) | |
knitr::kable(uncommon_trees, format = "html", align = "l") %>% | |
kable_styling(full_width = FALSE, bootstrap_options = "striped") | |
uncommon_tree_locations <- trees %>% # isolate lat longs | |
filter(SPECIESTYPE %in% uncommon_trees$Species) %>% | |
select(Species = SPECIESTYPE, longitude = LONGITUDE, latitude = LATITUDE) | |
widetree <- trees %>% # isolate lat long for the tree with the largest diameter | |
filter(DIAMETERinCENTIMETRES == max(trees$DIAMETERinCENTIMETRES)) %>% | |
select(Species = SPECIESTYPE, longitude = LONGITUDE, latitude = LATITUDE) | |
hightree <- trees %>% # isolate lat long for the tree with the largest diameter | |
filter(TREEHEIGHTinMETRES == max(trees$TREEHEIGHTinMETRES)) %>% | |
select(Species = SPECIESTYPE, longitude = LONGITUDE, latitude = LATITUDE) | |
map_uncommon <- bind_rows(uncommon_tree_locations, widetree, hightree) %>% # Give them notes for labelling | |
add_column(note = case_when(.$Species == "Handkerchief" ~ "Belfast's only Handkerchief tree", | |
.$Species == "Oak" ~ "Belfast's thickest tree (an oak)", | |
.$Species == "Alder" ~ "Belfast's highest tree (an alder)", | |
.$Species != "Handkerchief" & .$Species != "Oak" ~ .$Species)) %>% | |
add_column(foricons = case_when(.$Species == "Handkerchief" ~ "red", # a dummy column for assigning icons | |
.$Species == "Oak" | .$Species == "Alder" ~ "orange", | |
.$Species != "Handkerchief" & .$Species != "Oak" ~ "green")) | |
``` | |
What is a 'Handkerchief Tree'? Rather lovely [it turns out](https://www.rhs.org.uk/Plants/5364/Davidia-involucrata/Details). _Where_ is Belfast's sole handkerchief tree? Turns out it's in the Sir Thomas and Lady Dixon Park (red icon below). (The sole [Rauli](https://www.forestry.gov.uk/fr/infd-8cylkl) tree is in Belfast Zoo). | |
Finally, Belfast's thickest tree (by trunk diameter) is in Belfast City Cemetary on the Falls Road and its tallest tree is in Cherryvale park, off the Ravenhill road. See the orange icons in the map below. | |
```{r prepare_maps, echo = FALSE, cache=FALSE} | |
# Color icons (from https://stackoverflow.com/questions/32940617/change-color-of-leaflet-marker) | |
# Mapping guidance: from https://rstudio.github.io/leaflet/ | |
coloricons <- iconList( | |
red = makeIcon(iconUrl = "https://ciaranokelly.org/files/icons/leaf-red.png", | |
iconWidth = 38, | |
iconHeight = 95, | |
iconAnchorX = 22, | |
iconAnchorY = 94, | |
shadowUrl = "https://ciaranokelly.org/files/icons/leaf-shadow.png", | |
shadowWidth = 50, | |
shadowHeight = 64, | |
shadowAnchorX = 4, | |
shadowAnchorY = 62), | |
orange = makeIcon(iconUrl = "https://ciaranokelly.org/files/icons/leaf-orange.png", | |
iconWidth = 38, | |
iconHeight = 95, | |
iconAnchorX = 22, | |
iconAnchorY = 94, | |
shadowUrl = "https://ciaranokelly.org/files/icons/leaf-shadow.png", | |
shadowWidth = 50, | |
shadowHeight = 64, | |
shadowAnchorX = 4, | |
shadowAnchorY = 62), | |
green = makeIcon(iconUrl = "https://ciaranokelly.org/files/icons/leaf-green.png", | |
iconWidth = 38, | |
iconHeight = 95, | |
iconAnchorX = 22, | |
iconAnchorY = 94, | |
shadowUrl = "https://ciaranokelly.org/files/icons/leaf-shadow.png", | |
shadowWidth = 50, | |
shadowHeight = 64, | |
shadowAnchorX = 4, | |
shadowAnchorY = 62) | |
) | |
m <- leaflet(map_uncommon) %>% | |
addTiles() %>% # Add default OpenStreetMap map tiles | |
addMarkers(~longitude, ~latitude, popup = ~as.character(note), icon = ~coloricons[foricons]) | |
m | |
``` | |
Finally, out of curiosity, where are Belfast's sickest street trees? That is, as opposed to trees in parks. The map below contains street trees that are classed as low vigour and are either classed as being in poor condition or very poor condition or dying: | |
```{r sicktrees} | |
sicktrees <- trees %>% filter(TYPEOFTREE == "StreetTree") %>% | |
filter(VIGOUR == "Low" & (CONDITION == "Poor" | CONDITION == "Very Poor" | CONDITION == "Dying")) %>% | |
select(Species = SPECIESTYPE, longitude = LONGITUDE, latitude = LATITUDE) | |
``` | |
```{r mapsicktrees,echo = FALSE, cache=FALSE} | |
m2 <- leaflet(sicktrees) %>% | |
addTiles() %>% # Add default OpenStreetMap map tiles | |
addCircles | |
m2 | |
``` | |
`r nrow(sicktrees)` street trees in Belfast meet both these conditions. While street trees are clusterd in general there do seem to be some streets with a lot of sick trees. Illness clusters too I imagine. In terms of species, we should perhaps worry about Belfast's few Hawthorn bushes, but I can't see a good pattern. A bit more digging might help (or not)... | |
```{r sick by species} | |
# Create tibbles of healthy and sick trees by species and age | |
health_by_species <- trees %>% filter(TYPEOFTREE == "StreetTree") %>% | |
add_column(health = ifelse(.$VIGOUR == "Low" & (.$CONDITION == "Poor" | .$CONDITION == "Very Poor" | .$CONDITION == "Dying"), "sick", "healthy")) %>% | |
group_by(SPECIESTYPE, health) %>% | |
summarise(count = n()) | |
sick_by_species <- health_by_species %>% | |
filter(health == "sick") %>% ungroup | |
healthy_by_species <- health_by_species %>% | |
filter(health == "healthy") %>% ungroup | |
species_health <- left_join(healthy_by_species, sick_by_species, by = "SPECIESTYPE") %>% | |
select(Species = SPECIESTYPE, Healthy = count.x, Sick = count.y) %>% | |
mutate(Sick = replace_na(Sick, as.integer(0))) %>% | |
mutate(Total = Healthy + Sick) %>% | |
filter(Total > 9) %>% | |
filter(Species != "N/A") %>% | |
select(Species, Total, Healthy, Sick) %>% | |
mutate(`Sick %` = as.integer((Sick/Total)*100)) %>% | |
arrange(desc(`Sick %`)) %>% | |
slice(1:15) | |
knitr::kable(species_health, format = "html", align = "l") %>% | |
kable_styling(full_width = FALSE, bootstrap_options = "striped") | |
``` | |
Gist with code [here](https://gist.github.com/cokelly/46523efe5b65a4a5ac229b1cee49276f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment