library(tidyverse)
library(eurostat)
library(sf)
library(ggthemes)
library(rvest)
library(ggmap)
Overview
Eurostat
data with R. I used the {eurostat}
package to shows European Child and Youth Population
.
Load Libraries
Eurostat Geospatial
<- get_eurostat_geospatial(resolution = 10,
eu_geo nuts_level = 0,
year = 2016)
%>%
eu_geo ggplot() +
geom_sf()
search_eurostat("youth")
Europe Youth Data
<- get_eurostat("yth_demo_010", time_format = "num") yth_demo_010
<- yth_demo_010%>%
yth08_20 filter(age=="TOTAL",
=="T",
sex%in%c(2008,2022))%>%
timeselect(geo,time,sex,values)
%>%dim yth08_20
<- yth08_20%>%
data inner_join(eu_geo, by = "geo") %>%
st_as_sf()
Precentage of Change in Youths (2008-2022)
<- data%>%
ydata ::clean_names()%>%
janitormutate(name_latn=str_to_title(name_latn))%>%
select(geo,geometry,sex,time,values,name_latn)%>%
pivot_wider(names_from = "time",values_from = "values",names_prefix = "Y")%>%
mutate(change=round((as.numeric(Y2022)-as.numeric(Y2008))/as.numeric(Y2008),3))
ydata
European Cities
<- read_html("https://en.wikipedia.org/wiki/List_of_European_cities_by_population_within_city_limits")
eu_cities
<- eu_cities%>%
eu_cities html_nodes("table") %>%
1]] %>%
.[[html_table(fill = TRUE)
<- eu_cities[,-1]
eu_cities%>% names() eu_cities
<- eu_cities %>%
eu_citiesmutate(City=str_replace_all(City, "\\[.*\\]",""))%>%
select(City,Country)
<- geocode(eu_cities$City)
city.geo <- cbind(eu_cities,city.geo) eu_cities
ggplot(ydata)+
geom_sf(aes(fill=change),inherit.aes = F)+
geom_sf(aes(color=geo),fill=NA,alpha=0.5)+
::geom_text_repel(data=eu_cities,
ggrepelaes(x=lon,y=lat,label=City),
size=3,color="#ebe7d8",
family="Roboto Condensed",
inherit.aes = F)+
scale_x_continuous(limits = c(-10, 35)) +
scale_y_continuous(limits = c(35, 65)) +
scale_fill_continuous(type = "viridis",
name = "% change",
guide = guide_colorbar(
direction = "vertical",
title.position = "top",
label.position = "right",
barwidth = unit(8, "pt"),
barheight = unit(50, "pt"),
ticks = TRUE))+
coord_sf(clip = "off")+
labs(color="Country Code",
title="European Child and Youth Population",
subtitle = "% change 2008-2022",
caption="#30DayMapChallenge 2023 Day 14 Europe\nDatasource: {eurostat} & Wikipedia | Map: @fgazzelloni")+
::theme_map()+
ggthemestheme(text=element_text(size=14,color="#ebe7d8",family="Roboto Condensed"),
plot.title = element_text(face="bold",hjust = -1),
plot.caption = element_text(hjust = 0.5,size=9),
legend.background = element_blank(),
legend.position = c(1.1,0.3),
legend.title = element_text(size=8),
legend.text = element_text(size=6),
legend.key.size = unit(5,units = "pt"))
ggsave("day14_europe.png",height = 5,bg="#121007")