Sur base du rapport Reuters Institute Digital News 2021 j’ai constitué plusieurs visualisation des statistiques.
Les données de base du pdf ont été retranscrite pour faciliter les essais dans une feuille de calcul google en accès libre.
Le code est en R. Il s’agit avant tout d’un exercice.
Vue géographique de la confiance en Europe
Pour y arriver:
- Charger les librairies
- Charger les données
- Créer la carte
- Associer les valeurs
- Dessiner le graphe
Charger les librairies
library(ggplot2)
library(dplyr)
library(tidyverse)
library(grid)
library(rworldmap)
library(googlesheets4)
Code language: R (r)
Charger les données
gs4_deauth()
data = read_sheet('https://docs.google.com/spreadsheets/d/1k12EiuEdgncTFxUEwQHM3yQ0I_51s1teQehgmTd2irk/edit?usp=sharing')
Code language: R (r)
Créer la carte
worldMap <- getMap()
europeanCountries <- intersect(c("Austria","Belgium","Bulgaria","Croatia","Cyprus",
"Czech Rep.","Denmark","Estonia","Finland","France",
"Germany","Greece","Hungary","Ireland","Italy","Latvia",
"Lithuania","Luxembourg","Malta","Netherlands","Norway","Poland",
"Portugal","Romania","Slovakia","Slovenia","Spain",
"Sweden","Switzerland","United Kingdom","Turkey"), data$Country)
indEU <- which(worldMap$NAME%in%europeanCountries)
Code language: R (r)
Extract longitude and latitude border’s coordinates of members states of E.U.
europeCoords <- lapply(indEU, function(i){
df <- data.frame(worldMap@polygons[[i]]@Polygons[[1]]@coords)
df$region =as.character(worldMap$NAME[i])
colnames(df) <- list("long", "lat", "region")
return(df)
})
europeCoords <- do.call("rbind", europeCoords)
Code language: R (r)
Créer la table des pays et confiance puis mettre à jour la carte avec les valeurs de confiance
europeanTable <- select(europe,Country,Trust)
europeCoords$value <- europeanTable$Trust[match(europeCoords$region,europeanTable$Country)]
Code language: R (r)
Dessiner la carte
P <- ggplot() + geom_polygon(data = europeCoords, aes(x = long, y = lat, group = region, fill = value),
colour = "black", size = 0.1) +
coord_map(xlim = c(-13, 35), ylim = c(32, 71))
P <- P + theme(panel.grid.minor = element_line(colour = NA),
#panel.background = element_rect(fill = NA, colour = NA),
axis.text.x = element_blank(),
axis.text.y = element_blank(), axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(), axis.title = element_blank(),
plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines"))
P <- P + scale_fill_gradient2(name = "Public Trust in Digital Media", low = "red", mid= "white", high = "dark green", na.value = "grey50", limits = c(0,100), midpoint = 50, aesthetics = "colour")
P
Code language: R (r)
Vue ordonnée de la confiance en Europe
Création d’un tibble Europe uniquement avec une colonne permettant de mettre en gras un pays (ici la Belgique) suivi de la création du graph
europe <- filter(data, grepl('Europe', Market, fixed=TRUE)) %>%
mutate(Country=fct_reorder(Country,Trust)) %>%
mutate(Face = ifelse(Country=="Belgium",'bold','plain'))
plot <- ggplot(europe, aes(x = Country, y= Trust, fill=Market, label=Trust))
plot + scale_fill_brewer(palette = 'Set3') +
geom_bar(stat = "Identity") +
geom_text(nudge_y = 3) +
theme(axis.text.y=element_text(face=with(europe, europe[order(Trust,Country),])$Face)) +
coord_flip()
Code language: R (r)