Title :” Ireland’s Median Rainfall in january 1850-2014
Author : Dimitri Tiani
Date: 01/17/2025
format : htlm
Self-contained-math : true
Self-contained: true
###set working directory where the data will be taken from and saved from
setwd(‘C:/Users/27736/Desktop/R data/Class Materials-20241230’)
###load library (sf) to read simple feauture ### load and read the data
load (‘Rainfall.Rdata’) library (sf)
station <- read_sf (‘weather_stations.geojson’)
###check the structure of the data
str (station)
###Calculating median for the 25 station. library (dplyr) library (tidyverse)
Rain_med <- rain %>% filter(Month == “Jan” & Year >= 1850 & Year <= 2014) %>% group_by(Station) %>% summarise(medrainfall = median(Rainfall, na.rm = TRUE))
barplot(Rain_med\(medrainfall,names= Rain_med\)Station, las= 3, col = “blue”)
station %>% left_join(Rain_med)-> station_median
library(tmap) library(sf)
stations_sf <- station_median %>% st_as_sf(coords=c(‘Long’,‘Lat’),crs=4326) tmap_mode(‘view’) + tm_shape(stations_sf) + tm_bubbles(size = “medrainfall”, col = “medrainfall”, palette = “viridis”, title.size = “Median Rainfall”, title.col = “Median Rainfall”) + tm_layout(title = “Median Rainfall by Station”, legend.outside = TRUE)
part 2
load (‘Rainfall.Rdata’)
###load dplyr and tidyverse for spatial data manipulation
library (dplyr) library (tidyverse) ###load sp for handling spatial data
library (sp) ### Install and load the drygraph which is great visual representation of time series.
install.packages(“dygraphs”) library(dygraphs) ### summary of all the four stations.
Cork_ts <- rain %>% filter(Station == “Cork Airport”) %>% group_by(Year, Month) %>% summarise(Rainfall = sum(Rainfall, na.rm = TRUE), .groups = “drop”) %>% pull(Rainfall) %>% ts(start = c(1850, 1), frequency = 12)
rain %>% filter(Station==“Belfast”) %>% summarise(Rainfall=sum(Rainfall),.by=c(Month)) %>% pull(Rainfall) %>% ts(start=c(1850,1),freq=12) -> bel_ts
rain %>% filter(Station==“Dublin Airport”) %>% summarise(Rainfall=sum(Rainfall),.by=c(Month)) %>% pull(Rainfall) %>% ts(start=c(1850,1),freq=12) -> dub_ts ### combine all the Rainfall time series into one serie for the dygraph visual represetation bod_ts <- cbind(bel_ts,Cork_ts,dub_ts)
Gal_ts <- rain %>% filter(Station == “University college Galway”) %>% group_by(Month) %>% summarise(Rainfall = sum(Rainfall, na.rm = TRUE), .groups = “drop”) %>% pull(Rainfall) %>% ts(start = c(1850, 1), frequency = 12)
bod_ts %>% dygraph(width = 900, height = 300) %>% dyRangeSelector() beducoal_ts<-cbind(bel_ts,dub_ts,Cork_ts,Gal_ts) View(beducoal_ts) ### the next step is to represent time serie using a dygraphy and dyrangeSelector
beducoal_ts %>% dygraph(width=900,height=300) %>% dyRangeSelector()