library(ggplot2)
library(viridis)
## Loading required package: viridisLite
library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(TSP)
## Warning: package 'TSP' was built under R version 4.0.2
library(data.table)
library(ggplot2)
library(Matrix)
library(tcltk)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:arules':
## 
##     intersect, recode, setdiff, setequal, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(devtools)
## Warning: package 'devtools' was built under R version 4.0.2
## Loading required package: usethis
## Warning: package 'usethis' was built under R version 4.0.2
library(purrr)
## 
## Attaching package: 'purrr'
## The following object is masked from 'package:data.table':
## 
##     transpose
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following objects are masked from 'package:Matrix':
## 
##     expand, pack, unpack
library(arulesViz)
## Warning: package 'arulesViz' was built under R version 4.0.2
## Loading required package: grid
## Registered S3 method overwritten by 'seriation':
##   method         from 
##   reorder.hclust gclus
setwd("C:/Users/Lenovo/Desktop")


######## prepare and clean the data #####################

data<-read.csv("acaps_covid19_government_measures_dataset.csv",header=T,encoding = 'UTF-8') 
head(data)
##    ID  Country ISO ADMIN_LEVEL_NAME PCODE REGION
## 1 250 Ethiopia ETH      Addis Ababa    NA Africa
## 2 251 Ethiopia ETH                     NA Africa
## 3 254 Ethiopia ETH                     NA Africa
## 4 747 Ethiopia ETH                     NA Africa
## 5 748 Ethiopia ETH                     NA Africa
## 6 750 Ethiopia ETH                     NA Africa
##                               LOG_TYPE                               CATEGORY
## 1 Introduction / extension of measures                 Public health measures
## 2 Introduction / extension of measures                 Public health measures
## 3 Introduction / extension of measures                 Public health measures
## 4 Introduction / extension of measures                      Social distancing
## 5 Introduction / extension of measures                      Social distancing
## 6 Introduction / extension of measures Governance and socio-economic measures
##                                              MEASURE TARGETED_POP_GROUP
## 1 Health screenings in airports and border crossings                 No
## 2                  Isolation and quarantine policies                Yes
## 3                                Awareness campaigns                 No
## 4                            Schools closure<U+00A0>                 No
## 5                            Limit public gatherings                 No
## 6                                  Economic measures                 No
##                                                                                   COMMENTS
## 1 Ethiopia begins screening at an Addis Ababa airport to curb the import of coronavirus.  
## 2            14 day quarantine for those have been in Hubei province in the last 14 days. 
## 3                                                   Sanitation and hygiene recommendations
## 4                 Schools at all levels will be closed except higher education instituions
## 5                                          Large gatherings banned, smaller need approval.
## 6                                          Budget for masks, soap, and other crucial items
##   NON_COMPLIANCE DATE_IMPLEMENTED      SOURCE SOURCE_TYPE
## 1 Not applicable            43914          AA       Media
## 2 Not applicable            43883  US Embassy  Government
## 3 Not applicable            43903       Ezega       Media
## 4 Not applicable            43906 Africa News       Media
## 5 Not applicable            43906 Africa News       Media
## 6 Not applicable            43906 Africa News       Media
##                                                                                                                   LINK
## 1                        https://www.aa.com.tr/en/africa/ethiopia-begins-airport-screening-against-china-virus/1712852
## 2                                                                       https://et.usembassy.gov/covid-19-information/
## 3                           https://www.ezega.com/News/NewsDetails/7819/Ethiopia-Reports-Its-First-Case-of-Coronavirus
## 4 https://www.africanews.com/2020/03/16/ethiopia-s-coronavirus-rules-crowd-ban-free-transport-regulate-essentials-etc/
## 5 https://www.africanews.com/2020/03/16/ethiopia-s-coronavirus-rules-crowd-ban-free-transport-regulate-essentials-etc/
## 6 https://www.africanews.com/2020/03/16/ethiopia-s-coronavirus-rules-crowd-ban-free-transport-regulate-essentials-etc/
##   ENTRY_DATE Alternative.source
## 1      43905                   
## 2      43905                   
## 3      43905                   
## 4      43906                   
## 5      43906                   
## 6      43906
## and then we can remove some columns that are not useful to our analyse
data<- data[,-which(names(data)%in%c("REGION","LOG_TYPE","PCODE",'ADMIN_LEVEL_NAME','TARGETED_POP_GROUP','NON_COMPLIANCE','LINK',
                                     "ENTRY_DATE Alternative.source","DATE_IMPLEMENTED","ENTRY_DATE",'Alternative.source'))]
head(data)
##    ID  Country ISO                               CATEGORY
## 1 250 Ethiopia ETH                 Public health measures
## 2 251 Ethiopia ETH                 Public health measures
## 3 254 Ethiopia ETH                 Public health measures
## 4 747 Ethiopia ETH                      Social distancing
## 5 748 Ethiopia ETH                      Social distancing
## 6 750 Ethiopia ETH Governance and socio-economic measures
##                                              MEASURE
## 1 Health screenings in airports and border crossings
## 2                  Isolation and quarantine policies
## 3                                Awareness campaigns
## 4                            Schools closure<U+00A0>
## 5                            Limit public gatherings
## 6                                  Economic measures
##                                                                                   COMMENTS
## 1 Ethiopia begins screening at an Addis Ababa airport to curb the import of coronavirus.  
## 2            14 day quarantine for those have been in Hubei province in the last 14 days. 
## 3                                                   Sanitation and hygiene recommendations
## 4                 Schools at all levels will be closed except higher education instituions
## 5                                          Large gatherings banned, smaller need approval.
## 6                                          Budget for masks, soap, and other crucial items
##        SOURCE SOURCE_TYPE
## 1          AA       Media
## 2  US Embassy  Government
## 3       Ezega       Media
## 4 Africa News       Media
## 5 Africa News       Media
## 6 Africa News       Media
########   Write the data out to NEW.csv
write.csv(data, file = "measure.csv")




Myfile="measure.csv"


MyData <- read.csv(Myfile,encoding = 'UTF-8')

str(MyData)
## 'data.frame':    46 obs. of  9 variables:
##  $ X          : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ ID         : int  250 251 254 747 748 750 1297 1298 1299 1300 ...
##  $ Country    : chr  "Ethiopia" "Ethiopia" "Ethiopia" "Ethiopia" ...
##  $ ISO        : chr  "ETH" "ETH" "ETH" "ETH" ...
##  $ CATEGORY   : chr  "Public health measures" "Public health measures" "Public health measures" "Social distancing" ...
##  $ MEASURE    : chr  "Health screenings in airports and border crossings" "Isolation and quarantine policies" "Awareness campaigns" "Schools closure<U+00A0>" ...
##  $ COMMENTS   : chr  "Ethiopia begins screening at an Addis Ababa airport to curb the import of coronavirus.  " "14 day quarantine for those have been in Hubei province in the last 14 days. " "Sanitation and hygiene recommendations" "Schools at all levels will be closed except higher education instituions" ...
##  $ SOURCE     : chr  "AA" "US Embassy" "Ezega" "Africa News" ...
##  $ SOURCE_TYPE: chr  "Media" "Government" "Media" "Media" ...
head(MyData)
##   X  ID  Country ISO                               CATEGORY
## 1 1 250 Ethiopia ETH                 Public health measures
## 2 2 251 Ethiopia ETH                 Public health measures
## 3 3 254 Ethiopia ETH                 Public health measures
## 4 4 747 Ethiopia ETH                      Social distancing
## 5 5 748 Ethiopia ETH                      Social distancing
## 6 6 750 Ethiopia ETH Governance and socio-economic measures
##                                              MEASURE
## 1 Health screenings in airports and border crossings
## 2                  Isolation and quarantine policies
## 3                                Awareness campaigns
## 4                            Schools closure<U+00A0>
## 5                            Limit public gatherings
## 6                                  Economic measures
##                                                                                   COMMENTS
## 1 Ethiopia begins screening at an Addis Ababa airport to curb the import of coronavirus.  
## 2            14 day quarantine for those have been in Hubei province in the last 14 days. 
## 3                                                   Sanitation and hygiene recommendations
## 4                 Schools at all levels will be closed except higher education instituions
## 5                                          Large gatherings banned, smaller need approval.
## 6                                          Budget for masks, soap, and other crucial items
##        SOURCE SOURCE_TYPE
## 1          AA       Media
## 2  US Embassy  Government
## 3       Ezega       Media
## 4 Africa News       Media
## 5 Africa News       Media
## 6 Africa News       Media
MyPlot1<-ggplot(MyData, aes(x=MEASURE, fill=MEASURE)) + 
   geom_bar(position="stack")+
   geom_text(stat='count',aes(label=..count..),vjust=2)+  #######vjust=2 ajust the data location
   ggtitle("MEASURE Labels")+
   theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) #####change x label's position

print(MyPlot1)

MyPlot2<-ggplot(MyData, aes(x=CATEGORY, fill=CATEGORY)) + 
    geom_bar(position="stack")+
    geom_text(stat='count',aes(label=..count..),vjust=2)+  #######vjust=2 ajust the data location
    ggtitle("CATAGORY Labels")+
    theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) #####change x label's position
print(MyPlot2)

MyPlot3<-ggplot(MyData, aes(x=SOURCE_TYPE, fill=SOURCE_TYPE)) + 
    geom_bar(position="stack")+
    geom_text(stat='count',aes(label=..count..),vjust=2)+  #######vjust=2 ajust the data location
    ggtitle("SOURCE_TYPE Labels")+
    theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) #####change x label's position
print(MyPlot3)