Priloha B - Rkod #Mali library(tidyverse) library(lubridate) library(dplyr) library(STAT) library(tibble) library(reactable) library(sparkline) library(ggpubr) library(ggmap) library(sf) library(raster) library(markdown) library(pivottabler) library(ggpubr) library(plotly) #převedení názvu stáhnutého souboru na jednodušší Mali1<-X2015_01_01_2020_06_30_Burkina_Faso_Mali_Niger #Renaming type of events do ČJ Mali1<-Mali1%>% mutate(event_type = dplyr::recode(event_type, Battles="Boje", `Explosions/Remote violence`="Exploze", `Protests`="Protesty", `Riots`="Výtržnosti", `Strategic developments`="Str. vývoj", `Violence against civilians`="Násilí proti civ.")) #All regions - Mali, BF, Niger #Geoprecision - Graf 1 Mali1%>% ggplot(aes(geo_precision, group=country)) + geom_bar(aes(y=..prop..), stat="count", alpha = 0.8)+ scale_y_continuous(labels=scales::percent) + ylab("Relativní četnost") + xlab("Stupeň přesnosti geolokace")+ facet_grid(country ~ event_type)+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com") #počty obětí a počty událostí #Graf 2 oběti násilných událostí Mali1%>% ggplot(aes(year, fatalities)) + geom_col(aes(), alpha = 0.8)+ facet_grid(country ~ event_type)+ scale_color_manual(values = c(Battles = "RED", `Explosions/Remote violence` = "PURPLE", Protests = "BLUE", Riots = "GREEN", `Strategic developments` = "BROWN", `Violence against civilians` = "BLACK"))+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com")+ ylab("Oběti") + xlab("Rok") Mali1%>% ggplot(aes(year)) + geom_bar(aes(), alpha = 0.8)+ facet_grid(country ~ event_type)+ scale_color_manual(values = c(Battles = "RED", `Explosions/Remote violence` = "PURPLE", Protests = "BLUE", Riots = "GREEN", `Strategic developments` = "BROWN", `Violence against civilians` = "BLACK"))+ theme_minimal()+ ggtitle("Počet násilných událostí Mali, Burkina, Niger") #Graf 3 Regiony s nejv. poctem obeti Mali1%>%filter(event_type%in%c("Boje", "Exploze", "Násilí proti civ."), admin1%in%c("Diffa", "Tillaberi", "Sahel", "Est", "Nord", "Centre-Nord", "Boucle du Mouhoun", "Gao", "Kidal", "Mopti", "Segou", "Tombouctou"))%>% ggplot(aes(year, fatalities, group=event_type)) + geom_col(aes(fill=event_type), alpha = 0.8)+ facet_wrap(country ~ admin1, as.table=T)+ scale_fill_manual(values = c(Boje = "DARKBLUE", `Exploze` = "GRAY", `Násilí proti civ.` = "BLACK"))+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com")+ ylab("Oběti") + xlab("Rok")+ labs(fill = "Typ události") Mali1%>% ggplot(aes(event_type, fill=factor(geo_precision)))+ geom_bar(position="fill")+ geom_text(aes(label=scales::percent(..count../sum(..count..))), stat='count',position=position_fill(vjust=0.5)) Mali1%>% ggplot(aes(event_type, fill=factor(time_precision)))+ geom_bar(position="fill")+ geom_text(aes(label=scales::percent(..count../sum(..count..))), stat='count',position=position_fill(vjust=0.5)) #Mapa1 / nasilne udalosti 2015/2020 vyvoj v case ggplot(MBFN.map, aes(x=long, y=lat))+ geom_polygon(aes(group=group, fill=region), col="BLACK", fill="FALSE", alpha =0.5)+ geom_point(aes(longitude, latitude, size=fatalities, col=event_date), alpha=0.8, data = Mali1)+ coord_cartesian(xlim = c(-13, 16), ylim = c(9, 25))+ facet_wrap(.~event_type, ncol = 3)+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com", size="Oběti", col="Datum") ggplot(MBFN.map, aes(x=long, y=lat))+ geom_polygon(aes(group=group, fill=region), col="BLACK", fill="FALSE", alpha =0.5)+ geom_density2d(aes(longitude, latitude, col=event_type), alpha=1, data = Mali1)+ coord_cartesian(xlim = c(-13, 16), ylim = c(9, 25))+ facet_wrap(.~year, ncol = 3)+ theme_minimal()+ ggtitle("Násilné události, 2015-2020") #pokud jste převedli názvy kategorií eventů do čj, zadejte české názvy (boje, exploze atd....) Mali1BC<-Mali1%>%subset(event_type%in%c("Battles", "Violence against civilians")) #Akteri bitev, graf 4 Mali1BC%>%filter(event_type%in%"Battles", interaction%in%c("12", "13", "22", "23", "24", "28", "44"))%>% ggplot(aes(year, fatalities))+ geom_col()+ facet_grid(country~interaction)+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com")+ ylab("Oběti") + xlab("Rok") #"Aktéři násilí proti civilistům", Graf 5 Mali1BC%>%filter(event_type%in%"Violence against civilians", interaction%in%c("17", "27", "37", "47", "78"))%>% ggplot(aes(year, fatalities))+ geom_col()+ facet_grid(country~interaction)+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com")+ ylab("Oběti") + xlab("Rok") #Mopti Mopti<-Mali1%>%subset(admin1=="Mopti") MoptiBV<-Mopti%>%subset(event_type%in%c("Boje", "Násilí proti civ.", "Exploze")) Mopti20<-MoptiBV%>%subset(event_date > "2019-06-30") #nasledujici grafy jsou doplnkove, nejsou v clanku Mopti20%>%group_by(month=floor_date(event_date, "month"))%>% ggplot(aes(month, fatalities)) + geom_col(aes(), alpha = 0.8)+ facet_grid(event_type ~ admin2)+ scale_color_manual(values = c(Battles = "RED", `Explosions/Remote violence` = "PURPLE", Protests = "BLUE", Riots = "GREEN", `Strategic developments` = "BROWN", `Violence against civilians` = "BLACK"))+ theme_minimal()+ ggtitle("Oběti násilných událostí Mopti 1.1-30.6 2020")+ theme(axis.text.x = element_text(angle=45, hjust = 1)) Mopti20%>%group_by(month=floor_date(event_date, "month"))%>% ggplot(aes(month)) + geom_bar(aes(fill=actor1), alpha = 0.8)+ facet_grid(event_type ~ admin2)+ scale_color_manual(values = c(Battles = "RED", `Explosions/Remote violence` = "PURPLE", Protests = "BLUE", Riots = "GREEN", `Strategic developments` = "BROWN", `Violence against civilians` = "BLACK"))+ theme_minimal()+ ggtitle("Počet násilných událostí Mali, Burkina, Niger") #Graf 7 Nepřátelské interakce v bojích, srovnání 2. polovina 2019 a 1. polovina 2020 Mopti20%>%filter(event_type%in%"Battles", fatalities>1)%>% ggplot(aes(actor2, actor1))+ geom_count(aes(shape=as.factor(year)), stroke=1, alpha=0.7)+ scale_shape_manual(values=c("2019"=0, "2020"=1))+ scale_color_manual(values = c("2019" = "BLACK", "2020" = "BLACK"))+ scale_size(range =c(2, 11))+ theme_minimal()+ theme(axis.text.x = element_text(angle=45, hjust = 1))+ scale_x_discrete(label = function(x) stringr::str_trunc(x, 30))+ scale_y_discrete(label = function(y) stringr::str_trunc(y, 30))+ labs(shape="Rok")+ xlab("aktér2")+ ylab("aktér1") #Spoluprace akteru, neni v clanku Mopti20%>%filter(event_type%in%"Battles")%>% ggplot(aes(assoc_actor_1, actor1))+ geom_count(aes(shape=as.factor(year)), alpha=0.5)+ scale_size_area(max_size = 10)+ theme_minimal()+ ggtitle("Spolupracující aktéři v bojích - Mopti 2020")+ theme(axis.text.x = element_text(angle=45, hjust = 1))+ theme(axis.text.x = element_text(angle=45, hjust = 1))+ scale_x_discrete(label = function(x) stringr::str_trunc(x, 30))+ scale_y_discrete(label = function(y) stringr::str_trunc(y, 30)) #mapy Mopti #na4ten9 shapefilu pro admin jednotky Mali (ke stazeni https://data.humdata.org/dataset/administrative-boundaries-cod-mli) Mali3all<-st_read("C:/Users/Jan/Downloads/mli_admbndl_admALL_1m_dnct_itos_20190802.shp") #Mapa 2 - Násilné události v Mopti 19-20 Mali3all%>%filter(admLevel%in%c("0","1"))%>% ggplot() + geom_sf(color = "black", size=1) + geom_sf(color = "GRAY", size=0.8, data=Mali3all%>%filter(admLevel%in%"2")) + geom_point(aes(longitude, latitude, size=fatalities, col=event_date), alpha=0.6, data = Mopti20)+ geom_point(aes(-4.2, 14.5), size=2)+ scale_size(range = c(2, 12))+ facet_wrap(.~(event_type), ncol = 1)+ coord_sf(xlim = c(-6, 0), ylim = c(13, 16), expand = T)+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com", col="Datum", size="Oběti") #vypocet vzdalenosti od mesta Mopti (pomoci package(geosphere)) Mopti20<-Mopti20%>% rowwise() %>% mutate(D_Mopti = (distm(cbind(longitude, latitude), c(-4.2, 14.5), distGeo))/1000) # Graf 6, Vzdalenost boju od Mopti Mopti20%>%filter(event_type%in%c("Battles", "Explosions/Remote violence"), interaction%in%c("12", "13", "28"))%>% ggplot(aes(D_Mopti, actor1))+ geom_boxplot()+ geom_point(aes(size=fatalities, shape=event_type, col=as.factor(geo_precision)), position="jitter", alpha=0.8)+ scale_color_manual(values = c("1"="BLACK", "2"="GRAY32", "3"="BLUE"))+ scale_y_discrete(label = function(y) stringr::str_trunc(y, 30))+ theme_minimal()+ labs(caption="Zdroj dat: ACLED, https://www.acleddata.com")+ ylab("Aktér1") + xlab("Vzd Mopti (Km)")+ labs(col="Přesnost geolokace", shape="Typ události", size="Oběti") #Pivoty pt1<-qpvt(Mali1, rows=c("event_type", "country"), columns="year", summariseExpression="n()") pt1$renderPivot() #vztvoření reaktivní tabulky největších bojů - příloha C Mali1B<-Mali1%>%subset(event_type%in%"Battles") Mali1B<-Mali1B%>%subset(fatalities>19) Mali1B<-Mali1B%>%subset(interaction%in%"12") Mali1B<-Mali1B%>%subset(country%in%"Mali") reactable(Mali1B, groupBy = c("year", "admin1"), columns=list(data_id = colDef(name = "id", show = F), iso = colDef(name = "iso", show = F), event_id_cnty = colDef(name = "id2", show = F), event_id_no_cnty = colDef(name = "id3", show = FALSE), event_date = colDef(name = "Date", filterable = FALSE, width = 60), year = colDef(name = "year", show=T, filterable=T), time_precision = colDef(name = "tp", show = FALSE), event_type = colDef(name = "Event_t", show=F, filterable = F), sub_event_type = colDef(name = "Subevent", show = F), actor1 = colDef(name = "actor1", filterable = T), assoc_actor_1 = colDef(name = "Assoc_a1", show = T), inter1 = colDef(name = "inter1", show = F), actor2 = colDef(name = "actor2", show = T, filterable = T), assoc_actor_2 = colDef(name = "assoc_a2", show = T), inter2 = colDef(name = "inter2", show = F), interaction = colDef(name = "interact", show = F, filterable = T, width = 70), region = colDef(name = "Region", show = F), country = colDef(name = "Country", show = T), admin1 = colDef(name = "Admin1", filterable = T), admin2 = colDef(name= "admin2", filterable = T), admin3 = colDef(name = "admin3", show = F), location = colDef(name = "location", width = 70), latitude = colDef(name = "lat", show = F), longitude = colDef(name = "long", show = F), geo_precision = colDef(name = "geo_p", show = F), source = colDef(name = "source", show = F), source_scale = colDef(name = "source_sc", show = F), notes = colDef(name = "notes", filterable = F, show = T, width = 135), fatalities = colDef(name = "Fatal", filterable = F, aggregate = "sum", width = 65), timestamp = colDef(name = "tmst", show = F), iso3 = colDef(name = "iso3", show = F)), resizable = TRUE, filterable = TRUE, bordered = TRUE, showPageSizeOptions = TRUE, highlight = TRUE, striped = TRUE, wrap = T)