R/mobinternat.R

#' Transboundary movements network
#'
#' This function analyzes the dataset generated by the impcheckdata function and
#' produces an international mobility network with respect to a given country.
#' This network contains movements between the reference country and other countries.
#'
#' Cette fonction analyse le jeu de données généré par la fonction impcheckdata
#' et produit un réseau de mobilité internationale par rapport à un pays donné.
#' Ce réseau contient les mouvements entre le pays de référence et d'autres pays.
#'
#'
#' @import igraph
#' @importFrom graphics plot
#' @export mobinternat
#' @param x the data.frame containing the rawdata and generated by the impcheckdata function. \cr
#' Required columns: "ORIGINE_NOM", "ORIGINE_PAYS", "ORIGINE_LONGITUDE_X", "ORIGINE_LATITUDE_Y",
#' "DESTINATION_NOM", "DESTINATION_PAYS", "DESTINATION_LONGITUDE_X", "DESTINATION_LATITUDE_Y" and "EFFFECTIF"
#'
#' @param mon_pays the reference country between quotation marks, with the same writting than in x.
#' @keywords international movements network
#'
#' @examples
#' mobinternat(rawdata, "TUNISIE")
#'
mobinternat <- function(x, mon_pays){
  Origines <- x[,c("ORIGINE_NOM", "ORIGINE_PAYS", "ORIGINE_LONGITUDE_X", "ORIGINE_LATITUDE_Y")]
  Destinations <- x[,c("DESTINATION_NOM", "DESTINATION_PAYS", "DESTINATION_LONGITUDE_X", "DESTINATION_LATITUDE_Y")]
  names(Origines) <- names(Destinations) <- c("NOM","PAYS","LONGITUDE_X", "LATITUDE_Y")
  Origines$NOM <- as.character(Origines$NOM)
  Origines$PAYS <- as.character(Origines$PAYS)
  Destinations$NOM <- as.character(Destinations$NOM)
  Destinations$PAYS <- as.character(Destinations$PAYS)
  Localites <- unique(rbind(Origines, Destinations))
  Nom_Localites <- unique(Localites$NOM)
  x_tmp <- x[x$DESTINATION_PAYS == mon_pays & x$ORIGINE_PAYS != mon_pays,]
  Reseau_Internation <- graph_from_data_frame(x_tmp[,c("ORIGINE_NOM","DESTINATION_NOM")],
                                              vertices=Nom_Localites, directed=TRUE)
  E(Reseau_Internation)$weight <- x_tmp[,c("EFFFECTIF")]
  plot(Reseau_Internation)
  Reseau_Internation
}
Pachka/AQCR_SNA_Package documentation built on May 11, 2019, 7:26 p.m.