I’ve been working on creating graphs along my final project of the year which was about a statistical and economic analysis of the Tunisian economy. I want to share with you a graph showing the distribution of foreigners residing in Tunisia over years and to analyze it. I resort to the R software using the package ggplot2. I explore data from the Tunisian General Census of Population and Housing done in 2014 and provided by the National Institute of Statistics.

Here’s my dataset:

library(DT)

data=read.table(file=file.choose(),header=TRUE,sep=";")

datatable(data,class='compact',options=list(columnDefs=list(list(className ='dt-center',targets='_all')),
initComplete = JS("function(settings,json){","$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});","}")
))

Here’s the graph:

library(ggplot2) 

data$Year<-as.factor(data$Year)
ggplot(data,aes(x=Nationalities,y=Population,fill=Year))+
geom_bar(stat="identity",position=position_dodge(),width=1)+ylab("Foreigners(in thousands)")+ggtitle("Distribution of foreigners residing in Tunisia over years")+theme_bw()+theme(axis.text.x = element_text(angle=25))+scale_fill_manual(values=c("#3182bd","#9ecae1"))

Analysis of the output:

From 2004 to 2014, foreign nationals were recorded as residing in Tunisia and their number rose from 35192 to 53490.

Some nationalities such as Algerians, for instance, remained high with 9996 in 2014 and they came especially during holidays’periods.

The number of French residents in Tunisia was increasing from 4612 in 2004 to 8284 in 2014.

Libyan People were presented as well with a great increase from 1738 in 2004 to 8772 in 2014. They were escaping the civil war in their country.