-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigital world.qmd
1337 lines (1071 loc) · 39.3 KB
/
Digital world.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Digital world"
format: html
editor: visual
---
# Packages
```{r}
require(conflicted)
require(restatapi)
require(giscoR)
require(data.table)
require(chron)
require(reshape2)
require(kableExtra)
require(tidyverse)
require(tmap)
require(highcharter)
require(plotly)
conflicts_prefer(dplyr::filter)
```
# Young People - digital world
<https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Young_people_-_digital_world>
## Figure 1
People who used the internet on a daily basis, 2023 <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:People_who_used_the_internet_on_a_daily_basis,>*2023*(%25).png
### Retrieving data
```{r}
id3="isoc_ci_ifp_fu"
date2=2023
eu_cc<-get("cc",envir=.restatapi_env)$EU27_2020
efta_cc<-c("CH","NO","IS","LI")
data3=get_eurostat_data(id3, filters = list(time=date2, indic_is="I_IDAY", ind_type=c("IND_TOTAL","Y16_29"), unit="PC_IND"),
label=T,
ignore.case=T,
exact_match=T,
perl=T,
stringsAsFactors=F,
force_local_filter=T)
dsd3<-as.data.table(get_eurostat_dsd(id3))[concept=="geo",c("code","name")]
data3<-merge(data3,
dsd3,
by.x="geo",
by.y="name",
all.x=T,
all.y = F)
data3 <- data3[!code %in% c("EA19", "EA18", "EA",
"EU28", "EU27_2007", "EU")]
data3$geo<-gsub(" \\(.*\\)","",data3$geo)
data3$geo<-gsub("^Eu.*","EU",data3$geo)
name_ord <- data3[(code %in% eu_cc) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_eu<-name_ord[order(values)]$geo
name_ord<-data3[(code %in% efta_cc) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_efta<-name_ord[order(values)]$geo
name_ord<-data3[!(code %in% c(efta_cc,eu_cc,"EU27_2020")) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_othr<-name_ord[order(values)]$geo
name_ord<-c(name_ord_othr, " " ,name_ord_efta, " " ,name_ord_eu, " ", "EU")
data3 <- data3 |>
select(geo, ind_type, values) |>
mutate(ind_type = recode(ind_type,
"Individuals, 16 to 29 years old" = "Young people aged 16-29 years", "All Individuals"="Adult population")) |>
(\(df){
dt_sep <- data.table::data.table(
geo = c(" ", " ", " "),
ind_type = rep("Young people aged 16-29 years", 3),
values = rep(NA, 3)
)
rbind(df, dt_sep)
})()
data3$geo <- factor(data3$geo,levels = rev(name_ord))
data3$ind_type <- factor(data3$ind_type, levels = c("Young people aged 16-29 years", "Adult population"))
data3 <- data3 %>%
mutate(
geo = recode(
geo,
"Iceland" = "Iceland (\U00B9)",
"North Macedonia" = "North Macedonia (\U00B9)"
)
)
```
### Plot
```{r}
p1=ggplot(data = data3, aes(x = geo, y = values, fill = ind_type)) +
theme_minimal() +
geom_bar(stat = "identity", position = "dodge", width = 0.5) +
scale_fill_manual(values = c("#B09120", "#2644A7"),
labels = c("Young people aged 16-29 years", "Adult population")) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, max(data3$values, na.rm = TRUE) + 5),
breaks = seq(0, max(data3$values, na.rm = TRUE) + 5, 5)) +
theme_bw() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.border = element_blank(),
axis.line.y = element_blank(),
axis.line.x = element_line(colour = "black", linetype = "solid"),
plot.caption = element_text(hjust = 0),
plot.title = element_text(hjust = 0, face = "bold"),
legend.position = "bottom",
legend.title = element_blank()
) +
labs(
title = "People who used the internet on a daily basis, 2023",
caption = "\n(\U00B9) Data from 2021 \n(\U00B9) Data from 2022 \nSource: Eurostat (online data code: isoc_ci_ifp_fu)"
) +
theme(
legend.title = element_blank(), # Remove legend title
legend.position = "bottom", # Place legend below the plot
plot.caption = element_text(hjust = 0, face = "italic")
)
# Save the plot
output_file <- "digital_world/p1.png"
ggsave(filename = output_file, plot = p1, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Figure 2
People who participated on social networking sites, 2023 <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:Figure_2_People_who_participated_in_social_networks,>*2023*(%25).png
### Retrieving data
```{r}
id4="isoc_ci_ac_i"
date3=2023
u_cc<-get("cc",envir=.restatapi_env)$EU27_2020
efta_cc<-c("CH","NO","IS","LI")
data4=get_eurostat_data(id4, filters = list(time=date3, indic_is="I_IUSNET", ind_type=c("IND_TOTAL","Y16_29"), unit="PC_IND"),
label=T,
ignore.case=T,
exact_match=T,
perl=T,
stringsAsFactors=F,
force_local_filter=T)
dsd4<-as.data.table(get_eurostat_dsd(id4))[concept=="geo",c("code","name")]
data4<-merge(data4,
dsd4,
by.x="geo",
by.y="name",
all.x=T,
all.y = F)
data4 <- data4[!code %in% c("EA19", "EA18", "EA",
"EU28", "EU27_2007", "EU")]
data4$geo<-gsub(" \\(.*\\)","",data4$geo)
data4$geo<-gsub("^Eu.*","EU",data4$geo)
name_ord <- data4[(code %in% eu_cc) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_eu<-name_ord[order(values)]$geo
name_ord<-data4[(code %in% efta_cc) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_efta<-name_ord[order(values)]$geo
name_ord<-data4[!(code %in% c(efta_cc,eu_cc,"EU27_2020")) & (ind_type=="Individuals, 16 to 29 years old")]
name_ord_othr<-name_ord[order(values)]$geo
name_ord<-c(name_ord_othr, " " ,name_ord_efta, " " ,name_ord_eu, " ", "EU")
data4 <- data4 |>
select(geo, ind_type, values) |>
mutate(ind_type = recode(ind_type,
"Individuals, 16 to 29 years old" = "Young people aged 16-29 years", "All Individuals"="Adult population")) |>
(\(df){
dt_sep <- data.table::data.table(
geo = c(" ", " ", " "),
ind_type = rep("Young people aged 16-29 years", 3),
values = rep(NA, 3)
)
rbind(df, dt_sep)
})()
data4$geo <- factor(data4$geo,levels = rev(name_ord))
data4$ind_type <- factor(data4$ind_type, levels = c("Young people aged 16-29 years", "Adult population"))
data4 <- data4 %>%
mutate(
geo = recode(
geo,
"Iceland" = "Iceland (\U00B9)",
"Albania" = "Albania (\U00B9)"
)
)
```
### Plot
```{r}
p2=ggplot(data = data4, aes(x = geo, y = values, fill = ind_type)) +
theme_minimal() +
geom_bar(stat = "identity", position = "dodge", width = 0.5) +
scale_fill_manual(values = c("#B09120", "#2644A7"),
labels = c("Young people aged 16-29 years", "Adult population")) +
scale_y_continuous(expand = c(0, 0),
limits = c(0, max(data3$values, na.rm = TRUE) + 5),
breaks = seq(0, max(data3$values, na.rm = TRUE) + 5, 5)) +
theme_bw() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.border = element_blank(),
axis.line.y = element_blank(),
axis.line.x = element_line(colour = "black", linetype = "solid"),
plot.caption = element_text(hjust = 0),
plot.title = element_text(hjust = 0, face = "bold"),
legend.position = "bottom",
legend.title = element_blank()
) +
labs(
title = "People who participated in social networks, 2023",
caption = "\n Note: for example, created a user profile, posted messages or other contributions; Social networks include, for example, Facebook, Youtube, Instagram, Tiktok, X (former Twitter \n(\U00B9) Data from 2021 \n(\U00B9) Data from 2022 \nSource: Eurostat (online data code: isoc_ci_ac_i)"
) +
theme(
legend.title = element_blank(), # Remove legend title
legend.position = "bottom", # Place legend below the plot
plot.caption = element_text(hjust = 0, face = "italic")
)
# Save the plot
output_file <- "digital_world/p2.png"
ggsave(filename = output_file, plot = p2, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Figure 3
People who used the internet for civic or political participation, 2023 <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:Figure_3_People_who_used_the_internet_for_civic_or_political_participation,>*2023*(%25).png
### Retrieving data
```{r}
#| eval: true
# Define parameters
id3="isoc_ci_ac_i"
date3=2021:2022
# Get country codes for EU and EFTA
eu_cc<-get("cc",envir=.restatapi_env)$EU27_2020
efta_cc<-c("CH","NO","IS","LI")
# Fetch the data from Eurostat
data3 <- get_eurostat_data(
id3,
filters = list(
ind_type = c("IND_TOTAL","Y16_29"),
indic_is = "I_IUCPP",
freq = "Annual",
unit = c("PC_IND")
),
date_filter = date3,
label = TRUE,
ignore.case = TRUE,
exact_match = TRUE,
perl = TRUE,
stringsAsFactors = FALSE,
force_local_filter = F,
keep_flags = T
)
# Filter the data
data3 <- data3 |>
filter(unit == "Percentage of individuals") |>
filter(time == 2022 | (time == 2021 & geo %in% c("Switzerland", "Iceland", "North Macedonia")))
# Get the data structure definition (DSD) for geographic codes
dsd<-as.data.table(get_eurostat_dsd(id3))[concept=="geo",c("code","name")]
# Merge data with the DSD
datafig3 <- merge(data3, dsd, by.x = "geo", by.y = "name", all.x = TRUE)
# Filter out codes
datafig3 <- datafig3[!code %in% c("EA19", "EA18", "EA", "EU28", "EU27_2007", "EU")]
# Clean geo column
datafig3$geo <- gsub(" \\(.*\\)", "", datafig3$geo)
datafig3$geo <- gsub("^Eu.*", "EU", datafig3$geo)
# Order the names
name_ord_eu <- datafig3 |>
filter(code %in% eu_cc,
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_efta <- datafig3 |>
filter(code %in% efta_cc,
unit == "Percentage of individuals",
ind_type =="Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_othr <- datafig3 |>
filter(!code %in% c(efta_cc, eu_cc, "EU27_2020"),
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord <- c(name_ord_othr, " ", name_ord_efta, " ", name_ord_eu, " ", "EU")
# Prepare the final dataset
datafig3 <- datafig3 |>
select(geo, ind_type, values) |>
mutate(ind_type = recode(ind_type,
"Individuals, 16 to 29 years old" = "Young people aged 16-29 years", "All Individuals"="Adult population")) |>
add_row(geo = c(" ", " ", " "),
ind_type = "Adult population",
values = NA)
# Factorize geo and ind_type
datafig3$geo <- factor(datafig3$geo,levels = rev(name_ord))
datafig3$ind_type <- factor(datafig3$ind_type, levels = c("Young people aged 16-29 years", "Adult population"))
# Recode specific geo values
datafig3 <- datafig3 |>
mutate(geo = recode(geo,
"EU" = "EU (\U00B9)",
"Ireland" = "Ireland (\U00B9)(\U00B2)",
"Germany"= "Germany (\U00B9)",
"Iceland" = "Iceland (\U00B3)",
"Switzerland" = "Switzerland (\U00B3)",
"Albania"="Albania (\U00B3)",
"North Macedonia" = "North Macedonia(\U00B3)",
))
```
### Plot
```{r}
#| eval: true
# Define color palette
colors <- c("#B09120", "#2644A7")
# Define title, subtitle, and caption
title=paste0("People who used the internet for civic or political participation, \n ", tail(date3, n = 1))
subtitle=paste0("order by young people aged 16-29 years \n(%)")
caption=paste0("Note: for example, expressing opinions on civic or political issues or taking part in online consultations or voting to
\ndefine civic or political issues
\n(\U00B9) Break in time series.
\n(\U00B2) Low reliability for young people.
\n(\U00B3) Data from 2021.
\nSource: Eurostat (online data code: ",id3, ")")
# Create the plot
p3 <- ggplot(data = datafig3, aes(x = geo, y = values, fill = ind_type)) +
geom_bar(stat = "identity", position = "dodge", width = 0.5) +
scale_fill_manual(values = colors) +
scale_y_continuous(
expand = c(0, 0),
limits = c(0, max(data3$values) + 5),
breaks = seq(0, max(data3$values) + 5, 5)
) +
theme_bw() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.border = element_blank(),
axis.line.y = element_blank(),
axis.line.x = element_line(colour = "black", linetype = "solid"),
plot.caption = element_text(hjust = 0),
plot.title = element_text(hjust = 0, face = "bold"),
legend.position = "bottom",
legend.title = element_blank()
) +
labs(
title = title,
subtitle = subtitle,
caption = caption
)
# Save the plot
output_file <- "digital_world/p3.png"
ggsave(filename = output_file, plot = p3, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Figure 4
People who used the internet for doing an online course, 2023 <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:People_who_used_the_internet_for_doing_an_online_course,>*2023_order_by_young_people_aged_16-29_years*(%25).png
### Retrieving data
```{r}
#| eval: true
# Define parameters
id4="isoc_ci_ac_i"
date4=2021:2022
# Get country codes for EU and EFTA
eu_cc<-get("cc",envir=.restatapi_env)$EU27_2020
efta_cc<-c("CH","NO","IS","LI")
# Fetch the data from Eurostat
data4 <- get_eurostat_data(
id4,
filters = list(
ind_type = c("IND_TOTAL","Y16_29"),
indic_is = "I_IUOLC",
freq = "Annual",
unit = c("PC_IND")
),
date_filter = date4,
label = TRUE,
ignore.case = TRUE,
exact_match = TRUE,
perl = TRUE,
stringsAsFactors = FALSE,
force_local_filter = F,
keep_flags = T
)
# Filter the data
data4 <- data4 |>
filter(unit == "Percentage of individuals") |>
filter((time == 2022 & !(geo %in% c("Albania")) ) | (time == 2021 & geo %in% c("Switzerland", "Iceland", "North Macedonia", "Albania")))
# Get the data structure definition (DSD) for geographic codes
dsd<-as.data.table(get_eurostat_dsd(id4))[concept=="geo",c("code","name")]
# Merge data with the DSD
datafig4 <- merge(data4, dsd, by.x = "geo", by.y = "name", all.x = TRUE)
# Filter out codes
datafig4 <- datafig4[!code %in% c("EA19", "EA18", "EA", "EU28", "EU27_2007", "EU")]
# Clean geo column
datafig4$geo <- gsub(" \\(.*\\)", "", datafig4$geo)
datafig4$geo <- gsub("^Eu.*", "EU", datafig4$geo)
# Order the names
name_ord_eu <- datafig4 |>
filter(code %in% eu_cc,
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_efta <- datafig4 |>
filter(code %in% efta_cc,
unit == "Percentage of individuals",
ind_type =="Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_othr <- datafig4 |>
filter(!code %in% c(efta_cc, eu_cc, "EU27_2020"),
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord <- c(name_ord_othr, " ", name_ord_efta, " ", name_ord_eu, " ", "EU")
# Prepare the final dataset
datafig4 <- datafig4 |>
select(geo, ind_type, values) |>
mutate(ind_type = recode(ind_type,
"Individuals, 16 to 29 years old" = "Young people aged 16-29 years", "All Individuals"="Adult population")) |>
add_row(geo = c(" ", " ", " "),
ind_type = "Adult population",
values = NA)
# Factorize geo and ind_type
datafig4$geo <- factor(datafig4$geo,levels = rev(name_ord))
datafig4$ind_type <- factor(datafig4$ind_type, levels = c("Young people aged 16-29 years", "Adult population"))
# Recode specific geo values
datafig4 <- datafig4 |>
mutate(geo = recode(geo,
"Ireland" = "Ireland (\U00B9)",
"Iceland" = "Iceland (\U00B2)",
"Switzerland" = "Switzerland (\U00B2)",
"Albania"="Albania (\U00B2)",
"North Macedonia" = "North Macedonia(\U00B2)"
))
```
### Plot
```{r}
#| eval: true
# Define color palette
colors <- c("#B09120", "#2644A7")
# Define title, subtitle, and caption
title=paste0("People who used the internet for doing an online course, ",tail(date4, n = 1))
subtitle=paste0("order by young people aged 16-29 years \n(%)")
caption=paste0("\n(\U00B9) Low reliability for young population
\n(\U00B2) Data from 2021.
\nSource: Eurostat (online data code: ",id4, ")")
# Create the plot
p4 <- ggplot(data = datafig4, aes(x = geo, y = values, fill = ind_type)) +
geom_bar(stat = "identity", position = "dodge", width = 0.5) +
scale_fill_manual(values = colors) +
scale_y_continuous(
expand = c(0, 0),
limits = c(0, max(data4$values) + 5),
breaks = seq(0, max(data4$values) + 5, 5)
) +
theme_bw() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.border = element_blank(),
axis.line.y = element_blank(),
axis.line.x = element_line(colour = "black", linetype = "solid"),
plot.caption = element_text(hjust = 0),
plot.title = element_text(hjust = 0, face = "bold"),
legend.position = "bottom",
legend.title = element_blank()
) +
labs(
title = title,
subtitle = subtitle,
caption = caption
)
# Save the plot
output_file <- "digital_world/p4.png"
ggsave(filename = output_file, plot = p4, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Figure 5
Percentage of individuals who have verified the information or content found on internet, 2023 order by young people aged 16-29 years <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:Figure_5_Percentage_of_individuals_who_have_verified_the_information_or_content_found_on_the_internet,>*2023*(%25).png
### Retrieving data
```{r}
#| eval: true
# Define parameters
id5="isoc_sk_edic_i21"
date5=2021
# Get country codes for EU and EFTA
eu_cc<-get("cc",envir=.restatapi_env)$EU27_2020
efta_cc<-c("CH","NO","IS","LI")
# Fetch the data from Eurostat
data5 <- get_eurostat_data(
id5,
filters = list(
ind_type = c("IND_TOTAL","Y16_29"),
indic_is = "I_TIC",
freq = "Annual",
unit = c("PC_IND")
),
date_filter = date5,
label = TRUE,
ignore.case = TRUE,
exact_match = TRUE,
perl = TRUE,
stringsAsFactors = FALSE,
force_local_filter = F,
keep_flags = T
)
# Get the data structure definition (DSD) for geographic codes
dsd<-as.data.table(get_eurostat_dsd(id5))[concept=="geo",c("code","name")]
# Merge data with the DSD
datafig5 <- merge(data5, dsd, by.x = "geo", by.y = "name", all.x = TRUE)
# Filter out codes
datafig5 <- datafig5[!code %in% c("EA19", "EA18", "EA", "EU28", "EU27_2007", "EU")]
# Clean geo column
datafig5$geo <- gsub(" \\(.*\\)", "", datafig5$geo)
datafig5$geo <- gsub("^Eu.*", "EU", datafig5$geo)
# Order the names
name_ord_eu <- datafig5 |>
filter(code %in% eu_cc,
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_efta <- datafig5 |>
filter(code %in% efta_cc,
unit == "Percentage of individuals",
ind_type =="Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord_othr <- datafig5 |>
filter(!code %in% c(efta_cc, eu_cc, "EU27_2020"),
unit == "Percentage of individuals",
ind_type == "Individuals, 16 to 29 years old") |>
arrange(values) |>
pull(geo)
name_ord <- c(name_ord_othr, " ", name_ord_efta, " ", name_ord_eu, " ", "EU")
# Prepare the final dataset
datafig5 <- datafig5 |>
select(geo, ind_type, values) |>
mutate(ind_type = recode(ind_type,
"Individuals, 16 to 29 years old" = "Young people aged 16-29 years", "All Individuals"="Adult population")) |>
add_row(geo = c(" ", " ", " "),
ind_type = "Adult population",
values = NA)
# Factorize geo and ind_type
datafig5$geo <- factor(datafig5$geo,levels = rev(name_ord))
datafig5$ind_type <- factor(datafig5$ind_type, levels = c("Young people aged 16-29 years", "Adult population"))
# Recode specific geo values
datafig4 <- datafig4 |>
mutate(geo = recode(geo,
"Ireland" = "Ireland (\U00B9)"
))
```
### Plot
```{r}
#| eval: true
# Define color palette
colors <- c("#B09120", "#2644A7")
# Define title, subtitle, and caption
title=paste0("Percentage of individual who have verified the information or content \nfound on internet, ", date5)
subtitle=paste0("order by young people aged 16-29 years \n(%)")
caption=paste0("\n(\U00B9) Low reliability for young population
\nSource: Eurostat (online data code: ",id5, ")")
# Create the plot
p5 <- ggplot(data = datafig5, aes(x = geo, y = values, fill = ind_type)) +
geom_bar(stat = "identity", position = "dodge", width = 0.5) +
scale_fill_manual(values = colors) +
scale_y_continuous(
expand = c(0, 0),
limits = c(0, max(data5$values) + 5),
breaks = seq(0, max(data5$values) + 5, 5)
) +
theme_bw() +
theme(
axis.text.x = element_text(angle = 60, hjust = 1),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.border = element_blank(),
axis.line.y = element_blank(),
axis.line.x = element_line(colour = "black", linetype = "solid"),
plot.caption = element_text(hjust = 0),
plot.title = element_text(hjust = 0, face = "bold"),
legend.position = "bottom",
legend.title = element_blank()
) +
labs(
title = title,
subtitle = subtitle,
caption = caption
)
# Save the plot
output_file <- "digital_world/p5.png"
ggsave(filename = output_file, plot = p5, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Figure 6
Young people's internet use in the EU, selected indicators 2014-2023 <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:Figure_6_Young_people%27s_internet_use_in_the_EU,>*selected_activity_indicators,2014-2023*(%25).png
### Retrieving data
```{r}
id1<-"isoc_ci_ac_i"
date1 = 2014:2023
data1 <- get_eurostat_data(
id = id1,
filters = list(
indic_is = c("I_IUSNET", "I_IUNW1", "I_IUBK", "I_IUCPP", "I_IUOLC"),
ind_type = "IND_TOTAL",
geo = "EU27_2020",
time = date1,
unit = "PC_IND"
),
label = TRUE
)
data1 <- data1 %>%
group_by(indic_is) %>%
arrange(time) %>%
ungroup()
data1
```
### Plot
```{r}
indic_is_colors <- c("#2644A7", "#B09120", "#E04040", "#208486", "#388AE2")
p6 <- ggplot(data = data1, aes(x = time, y = values, color = indic_is)) +
geom_point(size = 1) +
geom_line(size = 1, aes(group = indic_is)) +
labs(
title = paste("Young people's internet use in the EU, selected activity indicators (", min(date1), "-", max(date1), ")"),
subtitle = "(%)",
caption = "\nData for 2020 are estimates\n2021: Break in Time Series\nSource: Eurostat (online data code: isoc_ci_ac_i)",
color = "Indicator",
x = NULL,
y = NULL
) +
theme_bw() +
theme(
legend.position = "bottom",
legend.box = "vertical",
panel.grid.major = element_blank(),
panel.grid.minor.x = element_line(linetype = "grey"),
plot.title = element_text(hjust = 0, size = 14, face = "bold"),
plot.subtitle = element_text(hjust = 0, size = 12),
plot.caption = element_text(hjust = 0, margin = margin(t = 10, unit = "pt"))
) +
ylim(0, 100) +
guides(color = guide_legend(ncol = 1)) +
scale_color_manual(values = indic_is_colors) +
labs(color = NULL)
# Save the plot
output_file <- "digital_world/p6.png"
ggsave(filename = output_file, plot = p1, width = 12, height = 8, dpi = 1000)
# Include the plot in the document
knitr::include_graphics(output_file)
```
## Map 1
Digital skills of young Europeans in 2023: Share of young people (16-29) with basic or above digital skills, <https://ec.europa.eu/eurostat/statistics-explained/index.php?title=File:Digital_skills_map.png>
### Retrieve Data
```{r}
map_id = "ISOC_SK_DSKL_I21"
# GET NUTS & COUNTRY BOUNDARIES
nuts3_sf <- giscoR::gisco_get_nuts(
nuts_level = "0",
resolution = "3",
year = "2021"
)
countries_sf <- giscoR::gisco_get_countries(
resolution = "3",
region = c("Asia", "Europe")
)
# FILTER COUNTRIES
non_eu_list <- c(
"AM", "AZ", "BA",
"BY", "GE", "MD",
"RU", "UA", "XK"
)
eu_list <- unique(nuts3_sf$CNTR_CODE)
eu_sf <- countries_sf %>%
dplyr::filter(CNTR_ID %in% eu_list)
non_eu_sf <- countries_sf %>%
dplyr::filter(CNTR_ID %in% non_eu_list)
# DIGITAL SKILLS DATA
indicator_df <- get_eurostat_data(
map_id,
filters = list(
ind_type = c("Y16_29"),
indic_is = "I_DSK2_BAB",
freq = "Annual",
unit = c("PC_IND"),
date_filter = c(2021:2023)
),
label = FALSE,
ignore.case = TRUE,
exact_match = TRUE,
perl = TRUE,
stringsAsFactors = FALSE,
force_local_filter = FALSE,
keep_flags = TRUE
)
# DATA
indicator_filtered_df <- indicator_df %>%
dplyr::select(geo, time, values) %>%
dplyr::rename("NUTS_ID" = "geo")
# DF TO WIDE FORMAT
indicator_wide_df <- indicator_filtered_df %>%
tidyr::pivot_wider(names_from = time, values_from = values)
# REPLACE MISSING VALUES
indicator_df_final <- indicator_wide_df %>%
dplyr::mutate(values = dplyr::if_else(is.na(`2023`), `2021`, `2023`)) %>%
dplyr::select(NUTS_ID, values)
# MERGE NUTS3 SF AND DF
mapping_sf <- nuts3_sf %>%
dplyr::left_join(indicator_df_final, by = "NUTS_ID")
# BREAKS, COLOR & BOUNDING BOX
ni <- classInt::classIntervals(mapping_sf$values, n = 5, style = "equal")$brks
brk <- ni %>%
append(max(mapping_sf$values)) %>%
head(-1)
breaks <- c(min(mapping_sf$values), brk) %>%
tail(-1)
cols <- hcl.colors(n = 6, palette = "Greens", rev = TRUE)
crs_lambert <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +datum=WGS84 +units=m +no_defs"
xmin <- -10.66
ymin <- 34.5
xmax <- 45
ymax <- 71
bbox <- sf::st_sfc(sf::st_polygon(list(cbind(
c(xmin, xmax, xmax, xmin, xmin),
c(ymin, ymin, ymax, ymax, ymin)
))), crs = 4326)
lambert_bbox <- sf::st_transform(bbox, crs = crs_lambert)
bb <- sf::st_bbox(lambert_bbox)
```
### Plot
```{r}
# # MAP
p <- ggplot(data = mapping_sf) +
geom_sf(data = subset(eu_sf, CNTR_ID == "RS"),
fill = "grey80", color = "black", size = .15) +
geom_sf(mapping = aes(fill = values),
color = NA, size = 0) +
geom_sf(data = eu_sf, color = "black",
size = .15, fill = "transparent") +
geom_sf(data = non_eu_sf, color = "black",
size = .15, fill = "grey80") +
geom_sf_text(data = mapping_sf,
aes(label = round(values, 0)),
size = 4,
color = "black",
check_overlap = TRUE,
nudge_y = 0.8,,
fontface = "bold",
path = T) +
coord_sf(crs = crs_lambert, xlim = c(bb["xmin"], bb["xmax"]), ylim = c(bb["ymin"], bb["ymax"])) +
scale_fill_gradientn(
colors = cols,
breaks = breaks,
labels = round(breaks, 0),
limits = c(min(mapping_sf$values), max(mapping_sf$values)),
na.value = "grey80"
) +
guides(
fill = guide_colorbar(
direction = "horizontal",
barheight = unit(2.5, units = "mm"),
barwidth = unit(50, units = "mm"),
label.position = "bottom",
label.hjust = 0,
nrow = 1,
byrow = TRUE
)
) +
theme_void() +
theme(
plot.background = element_rect(fill = "white", color = NA),
plot.caption = element_text(hjust = 0, size = 14),
plot.title = element_text(hjust = 0, face = "bold", size = 25),
plot.subtitle = element_text(hjust = 0, size = 15),
legend.position = c(0, 0.6),
legend.justification = c(0, 0),
legend.title = element_blank(),
legend.background = element_rect(fill = "white", color = NA),
legend.text = element_text(size = 10, color = "grey10")
) +
labs(
caption = paste0("Iceland, North Macedonia and Albania: data from 2021.",
"\nSource: Eurostat (online data code: ", map_id, ")\n"),
title = "Digital Skills of Young Europeans in 2023",
subtitle = "Share of 16-29 year olds with basic or above digital skills (%)\n"
)
# Save the plot with a specific background setting
output_file <- "digital_world/map1.png"
ggsave(filename = output_file, plot = p, width = 20, height = 12, dpi = 1000, bg = "white")