This github repository’s for a data visualization series

Author

ABDOUL OUDOUSS DIAKITE

1 Health facilities

Code
library(readr)
library(ggplot2)
library(viridis)
library(hrbrthemes)
StructuresSante <- read_csv("StructuresSante.csv", 
                            col_types = cols(...1 = col_skip()),show_col_types = F)
Region_Total =glue::glue("{StructuresSante$Region} : {StructuresSante$Total}")
StructuresSante$Region =Region_Total
StructuresSante=StructuresSante[-15,]
Region = rep(StructuresSante$Region,4)
Count =unlist(c(StructuresSante[,2:5]))
`Type de structure`=c(rep("Hôpital",14),rep("Centre de santé",14),
                    rep("Poste de santé",14),rep("Case de santé",14))
df = data.frame(Region,Count,`Type de structure`)


g1= ggplot(data = df,aes(x=Region,y=Count,group = `Type de structure`,
                         fill = `Type de structure`))+
  geom_bar(position="dodge", stat="identity",width=70)+
  scale_fill_brewer(palette = "Spectral")+
  geom_text(aes(label = Count,group = `Type de structure`),
            position=position_dodge2(width = 70,padding = 0.3),
            hjust=-0.2,
            size = 4,color = '#581845',fontface="bold.italic")+
  
  ggtitle("Inventaire des structures de santé au Sénégal (2019)") +
  labs(subtitle = 
       "Comme les phases précédentes, 
L’ECPSS 2019 est une enquête des structures de santé tant du secteur public que du secteur privé au Sénégal.
L’enquête a été menée dans toutes les structures de santé recensées (hôpitaux, centres de santé, et postes de santé),ainsi que les cases de santé liées aux postes de santé sélectionnés,
dans les 14 régions du pays. Les administrateurs et prestataires des services de santé de ces structures ont été interviewés ; 
les prestataires et les patients/clients venus en consultation pour des services de santé
spécifiques (consultation de l’enfant malade de moins de cinq ans et les consultations prénatales) 
ont été observés au cours des consultations et des interviews ont été menées avec des 
clients/ accompagnateurs d’enfants malades dont les consultations avaient été observées.",
caption = "Source : ANSD (ECPSS 2019)\n Crédit : Abdoul Oudouss DIAKITE")+
facet_wrap(~Region,nrow = 5)+
theme(plot.title  = element_text(color="#C70039", size=17, face="bold.italic"),
      plot.subtitle = element_text(color="black", size=10, face="italic"),
      axis.text.x  = element_blank(),
      axis.text.y  = element_blank(),
      panel.grid = element_blank(),
      axis.ticks.y = element_blank(),
      axis.ticks.x = element_blank(),
      panel.background = element_blank())+
  coord_flip()+
  xlab("") + ylab("")

2 Causes of deaths

Code
library(readxl)
library(ggplot2)
library(dplyr)
#fig1
#data
AllAgesFemale <- read_excel("AllAgesFemale.xlsx") %>% 
  arrange(`Death rate per 100 000 population`) %>% tail(10) %>% mutate(Cause=factor(Cause,Cause))
#Plot
fig1 = ggplot(data = AllAgesFemale,aes(x=Cause,
                                       y =`Death rate per 100 000 population`,
                                       fill =Cause))+
  geom_bar(stat="identity",show.legend = F,color = '#FFE4E3',size=.7)+
  coord_flip() +
  geom_text(aes(label=scales::comma(`Death rate per 100 000 population`)),
            hjust=0, nudge_y=-5,
            color = 'black',size = 4.5,fontface="bold") +
    labs(x="", y="Death rate per 100 000 women of all age",
       title="Top 10 causes of death in Senegal \nfor women aged all ages (2019)",
       subtitle="Data source : www.who.int \nTotal women of all ages : 8 349 929",
       caption="@Abdoul Oudouss Diakite")+
  hrbrthemes::theme_ipsum(grid = "X")

#fig2
#data
F20_24 <- read_excel("20-24Female.xlsx") %>% 
  arrange(`Death rate per 100 000 population`) %>% tail(10) %>% mutate(Cause=factor(Cause,Cause))
#Plot
fig2 = ggplot(data = F20_24,aes(x=Cause,y =`Death rate per 100 000 population`,fill =Cause))+
  geom_bar(stat="identity",show.legend = F,color = '#FFE4E3',size=.7)+
  annotate(geom = 'curve',
           x="Sickle cell disorders and trait", y =  25,
           xend = "Interpersonal violence",
           color ='black',
           yend = 7.6, 
           curvature = 0.2, arrow = arrow(length = unit(2, "mm")))+
  annotate(geom = 'text',
           x="Sickle cell disorders and trait", y = 22,
           label = 'Interpersonal violence ranks fourth',
           color = 'black',
           size = 4,hjust = "center",vjust='top',fontface="bold") +
  coord_flip() +
  geom_text(aes(label=`Death rate per 100 000 population`), hjust=0, nudge_y=-2.5,
            color = 'black',size = 4.5,fontface="bold") +
  labs(x="", y="Death rate per 100,000 women aged 20-24",
       title="Top 10 causes of death in Senegal \nfor women aged 20 to 24 years (2019)",
       subtitle="Data source : www.who.int \nTotal women aged 20-24 : 741 748",
       caption="@Abdoul Oudouss Diakite")+
  hrbrthemes::theme_ipsum(grid = "X")
fig1;fig2

3 Expots & Imports (Senegal)

Code
library(ggplot2)
library(magrittr)
library(readr)
#Load data
Data.SEN <- read_csv("SenegalIndicators.csv", 
                     skip = 4,show_col_types = F) %>% .[,-length(.)]

data1=as.data.frame(t(Data.SEN[Data.SEN$`Indicator Code`=='TX.VAL.MRCH.CD.WT',-(1:4)]))
data1$Date=rownames(data1)
names(data1)[1]=c('Exports')
data=as.data.frame(t(Data.SEN[Data.SEN$`Indicator Code`=='TM.VAL.MRCH.CD.WT',-(1:4)]))
data$Date=rownames(data)
names(data)[1]=c('Imports')
data=merge(data1,data,by = 'Date')
data = na.omit(data)
Code
ggplot(data = data,aes(x= as.numeric(Date))) +
  geom_col(aes(y=Imports),fill = "#FF5733",size = 50) +
  geom_col(aes(y=Exports),fill  ="#0A7104",size =50,width = 0.7) +
  labs(title = 'Senegal',subtitle = 'Imports & Exports (current US$)',caption = )+
  #Imports arrow
  annotate(geom = 'curve',
           x=1970, y = 2e+09,
           xend = 1980,
           color ='#622700',
           yend = data$Imports[data$Date=='1980'], 
           curvature = 0.2, arrow = arrow(length = unit(4, "mm")))+
  #Imports text
  annotate(geom = 'text',
           x=1970, y = 2.25e+09,
           label = 'Imports',
           color = '#FF5733',
           size = 5,hjust = "center",vjust='top',fontface="bold") +
  #Exports arrow
  annotate(geom = 'curve',
           x=1987, y = 2e+09,
           xend = 1987,
           color ='#043701',
           yend = data$Exports[data$Date=='1987'], 
           curvature = 0, arrow = arrow(length = unit(4, "mm")))+
  #Exports text
  annotate(geom = 'text',
           x=1987, y = 2.25e+09,
           label = 'Exports',
           color = '#0A7104',
           size = 5,hjust = "center",fontface="bold") +
  #2012's Exports arrow
  annotate(geom = 'curve',
           x=1993, y = 4e+09,
           xend = 2012,
           color ='#043701',
           yend = data$Exports[data$Date=='2012'], 
           curvature = 0.4, arrow = arrow(length = unit(4, "mm")))+
  #2012's Imports arrow
  annotate(geom = 'curve',
           x=1993, y = 4e+09,
           xend = 2012,
           color ='#622700',
           yend = data$Imports[data$Date=='2012'], 
           curvature = -0.4, arrow = arrow(length = unit(4, "mm")))+
  #2012's label
  annotate(geom = "label", x = 1993, 
           y = 4e+09, 
           label = paste0("Beginning of Macky Sall's presidential term",
                          "\n",
                          "Date : 2012","\n",
                          "Imports : ",data$Imports[data$Date=='2012'],
                          "\n",
                          "Exports : ",data$Exports[data$Date=='2012'],
                          "\n"),
           size = 2.1,hjust = "center",fill='#EBC894',fontface="bold")+
  #Max Exports arrow
  annotate(geom = 'curve',
           x=1970, y = 6e+09,
           xend =as.numeric(data$Date[which.max(data$Exports)]),
           color ='#89F400',
           yend = data$Exports[which.max(data$Exports)], 
           curvature = -0.35, arrow = arrow(length = unit(4, "mm")))+
  #Max Imports arrow
  annotate(geom = 'curve',
           x=1970, y = 6e+09,
           xend = as.numeric(data$Date[which.max(data$Imports)]),
           color ='#F40400',
           yend = data$Imports[which.max(data$Imports)], 
           curvature = -0.16, arrow = arrow(length = unit(4, "mm")))+
  #Max's label
  annotate(geom = "label", x = 1970,
           y = 6e+09,
           label = paste0("Maximum Exports&Imports",
                          "\n",
                          "Date :",data$Date[which.max(data$Imports)],"\n",
                          "Imports : ",data$Imports[which.max(data$Imports)],
                          "\n",
                          "Exports : ",data$Exports[which.max(data$Exports)],
                          "\n"),
           size = 2.1,hjust = "center",fill='#E5DC94',fontface="bold")+
  ggthemes::theme_wsj()

4 Covid 19 ( Senegal )

Code
# Load Covid Data
library(dplyr)
library(readr)
SEN.covid<-  read_csv("https://covid19.who.int/WHO-COVID-19-global-data.csv",
                      show_col_types = FALSE) %>% 
     .[.$Country=='Senegal',] %>% filter(Date_reported >= '2020-03-02')
Code
#ploting
library(ggplot2)
library(patchwork)
p1= ggplot(SEN.covid,aes(x=Date_reported)) +
  geom_col(aes(y = New_cases),color="darkblue") +
  annotate(geom = 'col', 
           x=SEN.covid[which.max(SEN.covid$New_cases),]$Date_reported,
           y=max(SEN.covid$New_cases),colour ="red",size =1) + 
  annotate(geom = 'curve',
           x=lubridate::ymd('2020-07-28'), y = max(SEN.covid$New_cases)-500,
           xend = SEN.covid[which.max(SEN.covid$New_cases)-2,]$Date_reported,
           color ='#BB6203',
           yend = max(SEN.covid$New_cases), 
           curvature = -0.4, arrow = arrow(length = unit(4, "mm"))) +
  annotate(geom = "label", x = lubridate::ymd('2020-07-28'), 
           y = max(SEN.covid$New_cases)-600, 
           label = paste0("Maximum number of cases : ",max(SEN.covid$New_cases),
                          "\n","Date : ",
                          SEN.covid[which.max(SEN.covid$New_cases)-1,]$Date_reported,
                          "\n"),
           size = 3.1,hjust = "center",fill='#FED5AA',fontface="bold")+
  labs(title = 'Senegal',subtitle = 'Daily covid19 cases',
       x='Date',y='New cases')+
  ggthemes::theme_tufte() 

p2 = ggplot(SEN.covid,aes(x=Date_reported)) +
  geom_col(aes(y = New_deaths),color="#3F3E46") +
  annotate(geom = 'col', 
           x=SEN.covid[which.max(SEN.covid$New_deaths),]$Date_reported,
           y=max(SEN.covid$New_deaths),colour ="#FF023F",size =1) +
   annotate(geom = 'curve',
           x=lubridate::ymd('2020-07-05'), y = max(SEN.covid$New_deaths)-10,
           xend = SEN.covid[which.max(SEN.covid$New_deaths)-2,]$Date_reported,
           color ='#041087',
           yend = max(SEN.covid$New_deaths), 
           curvature = -0.4, arrow = arrow(length = unit(4, "mm"))) +
  annotate(geom = "label", x = lubridate::ymd('2020-07-07'), 
           y = max(SEN.covid$New_deaths)-12, 
           label = paste0("Maximum number of deaths : ",max(SEN.covid$New_deaths),
                          "\n","Date : ",
                          SEN.covid[which.max(SEN.covid$New_deaths)-1,]$Date_reported,
                          "\n"),
           fill='#B2B3D2', size = 3,hjust = "center",fontface="bold")+
  labs(title = 'Senegal',subtitle = 'Daily deaths related to covid19',
       x='Date',y='New deaths')+
  ggthemes::theme_tufte()

p1;p2