10.2 Data!
10.2.1 Getting it
We get them from European Environment Agency
We are using annual averages of \(PM_2.5\) recorded at monitoring stations (2015, 2016,2017).
<- c("ID", "CountryOrTerritory", "ReportingYear", "UpdateTime",
my_colnames "StationLocalId", "SamplingPointLocalId", "SamplingPoint_Latitude",
"SamplingPoint_Longitude", "Pollutant", "AggregationType",
"Namespace", "Unit", "BeginPosition", "EndPosition",
"Validity", "Verification", "DataCoverage", "DataCapture",
"TimeCoverage", "AQValue")
<- read.csv("https://www.paulamoraga.com/assets/datasets/dataPM25.csv",
d skip = 1,
header = FALSE,
col.names = my_colnames)
10.2.2 Cleaning it
Data are in 4326 (lat/long)
<- d[, c(
d "ReportingYear", "StationLocalId",
"SamplingPoint_Longitude",
"SamplingPoint_Latitude",
"AQValue"
)]names(d) <- c("year", "id", "long", "lat", "value")
<- st_as_sf(data.frame(long = d$long, lat = d$lat),
p coords = c("long", "lat"))
st_crs(p) <- st_crs(4326)
<- st_transform(p, 25830)
p c("x", "y")] <- st_coordinates(p) # new coords in 25830
d[,
<- st_intersects(m, p) # return a sparse geometry binary predicate
ind <- d[ind[[1]], ] # it is a list with just "spain" so we simplify [[]] it d
We plot it!
ggplot(m) + geom_sf() + coord_sf(datum = NA) +
geom_point(
data = d, aes(x = x, y = y, color = value),
size = 2
+
) labs(x = "", y = "") +
scale_color_viridis() +
facet_wrap(~year) +
theme_bw()