#Import data
load('rainfall.RData')
library(knitr)
colnames(rain)[1] "Year" "Month" "Rainfall" "Station"
The “rainfall.RData” file consists of 2 objects and 14 variables across those objects. Data being used consist of precipitation data from 25 weather stations across Ireland for the period of 1850 to 2014. Of interest in this report, is the median rainfall for the month of January across this time span.
Data object ‘rain’ consists of four variables:
#Import data
load('rainfall.RData')
library(knitr)
colnames(rain)[1] "Year" "Month" "Rainfall" "Station"
Data object ‘stations’ consists of the following variables:
colnames(stations)[1] “Station” “Elevation” “Easting” “Northing” “Lat”
[6] “Long” “County” “Abbreviation” “Source”
Summary of data across 25 weather stations across Ireland:
range(rain$Year)[1] 1850 2014
paste(formatC(mean(rain$Rainfall),digits = 2,format = 'f'),'mm')[1] "90.97 mm"
paste(formatC(median(rain$Rainfall),digits = 2,format = 'f'),'mm')[1] "82.20 mm"
paste(formatC(sd(rain$Rainfall),digits = 2,format = 'f'),'mm')[1] "51.60 mm"
sum(is.na(rain) | rain == "")[1] 0
#| warning: false
#Objects of interest: rain & stations
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(sf))
#Calculate Median for January
rain %>% filter(Month == 'Jan') %>% group_by(Station) %>%
summarise(mdrain = median(Rainfall)) %>% left_join(stations) %>%
select(Station,Long,Lat,mdrain) %>%
st_as_sf(coords = c('Long','Lat'), crs = 4326) -> station_medianJoining, by = "Station"
#Generating of Map
library(tmap)
library(leaflet)
st_read('counties.geojson', quiet = TRUE) %>% st_transform(4326) -> counties
basemap <- leaflet::providers$Esri.WorldTerrain
station_median$mdrain_mm <- paste(station_median$mdrain, "mm")
colnames(station_median)[1] "Station" "mdrain" "geometry" "mdrain_mm"
tm_stack <- tmap_mode('view') +
tm_basemap(basemap) +
tm_shape(counties) + tm_borders() +
tm_shape(station_median) +
tm_dots(col = 'mdrain', popup.vars = c('Median:' = 'mdrain_mm'), scale = 2,
title = "Median Rainfall (mm)")tmap mode set to interactive viewing
pal <- colorBin(palette = 'YlOrRd', bins = c(60,80,100,120,140,160,180), pretty = TRUE,domain = station_median$mdrain)
tmap_leaflet(tm_stack) %>%
addCircleMarkers(data = station_median,
radius = ~ifelse(mdrain > 120, 14, 10),
color = ~pal(mdrain),
weight = 1,
stroke = FALSE, fillOpacity = 1) %>%
addMiniMap() %>%
addScaleBar(position = "bottomleft")Low median rainfall is observed in the Central to the East Central of Ireland as indicated by the lighter brown and small radius. Higher median rainfall is observed in the South West and the North West of the island as represented by the darker brown and larger radius. The North East of Ireland consists of low to moderate rainfall as represented by lighter orange and smaller radius. A moderate median rainfall is observed along the South East of Ireland as indicated by the orange colour and large radius. Weather stations recording median rainfall greater than 120 mm are represented by a larger radius. Therefore, most weather stations along the South East to the South West of Ireland, recorded a median rainfall above 120 mm for the month of January between 1850 to 2014
The HTML heading tags <h5> and </h5> had to be used to add a heading below the map as ‘##’ was appearing as plain text