This project introduces the January rainfall data of Ireland using an interactive map. The visualization showcases rainfall distribution across various weather stations, grouping them into distinct intervals for better comprehension.
This analysis uses two datasets to create a map visualizing rainfall patterns in Ireland:
Description: This dataset contains monthly rainfall measurements for weather stations across Ireland.
Purpose: To calculate the median January rainfall for each weather station.
Key Columns:
Description: This dataset provides metadata about the weather stations.
Purpose: To provide geographical and location-specific information for mapping.
Key Columns:
# Load the .RData file
load("rainfall.RData")
# Save the 'stations' data to a CSV file
write.csv(stations, "stations.csv", row.names = FALSE)
# Save the 'rain' data to a CSV file
write.csv(rain, "rain.csv", row.names = FALSE)
The following R code outlines the steps to process the data and generate the map:
# Load necessary libraries
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.4.2
stations <- read.csv("stations.csv")
rain <- read.csv("rain.csv")
# Calculate median rainfall for January at each station
median_rainfall <- rain %>%
filter(Month == "Jan") %>%
group_by(Station) %>%
summarize(MedianRainfall = median(Rainfall, na.rm = TRUE))
# Merge median rainfall with station data
stations_with_rainfall <- stations %>%
inner_join(median_rainfall, by = "Station")
# Define rainfall intervals and assign bright colors
stations_with_rainfall <- stations_with_rainfall %>%
mutate(
RainfallInterval = cut(
MedianRainfall,
breaks = c(0, 80, 100, 120, 140, 160, 180),
labels = c("0-80", "80-100", "100-120", "120-140", "140-160", "160-180"),
right = FALSE
)
)
# Define a manual bright color palette
color_palette <- c(
"0-80" = "#FF0000", # Bright red
"80-100" = "#FFFF00", # Bright yellow
"100-120" = "#00FF00", # Bright green
"120-140" = "#0000FF", # Bright blue
"140-160" = "#FF00FF", # Bright purple
"160-180" = "#ff8000" # Bright orange
)
# Add color column based on the rainfall interval
stations_with_rainfall$Color <- color_palette[as.character(stations_with_rainfall$RainfallInterval)]
# Create an interactive map using leaflet
leaflet(data = stations_with_rainfall) %>%
addTiles() %>% # Add base map tiles
addCircleMarkers(
lng = ~Long,
lat = ~Lat,
color = ~Color,
radius = ~sqrt(MedianRainfall), # Adjust radius based on rainfall level
stroke = TRUE,
fillOpacity = 0.9,
popup = ~paste0(
"<b>Station: </b>", Station, "<br>",
"<b>County: </b>", County, "<br>",
"<b>Median Rainfall (Jan): </b>", MedianRainfall, " mm"
)
) %>%
addLegend(
colors = unname(color_palette),
labels = names(color_palette),
title = "Rainfall Intervals (mm)",
position = "bottomright"
)
The map uses circle markers to represent each station. Each circle is color-coded based on the rainfall interval, with the color legend clearly showing the associated ranges.
Each station is represented by a colored circle, with the color corresponding to specific rainfall intervals (0-80, 80-100, 100-120, 120-140, 140-160, 160-180). Here’s a detailed discussion of the patterns visible in the map:
This project demonstrates the power of data visualization in uncovering climate trends. By leveraging R and leaflet, we created an interactive map that not only illustrates rainfall distribution but also highlights how geographical factors influence these patterns. Such insights are invaluable for policymakers, environmentalists, and researchers aiming to address climate-related challenges in Ireland.
The map highlights a clear gradient in rainfall distribution across Ireland:
This analysis provides valuable insights for weather-related planning, agriculture, and infrastructure development in Ireland.