Title: | Analysis of the International Trade Network |
---|---|
Description: | Functions to clean and process international trade data into an international trade network (ITN) are provided. It then provides a set a functions to undertake analysis and plots of the ITN (extract the backbone, centrality, blockmodels, clustering). Examining the key players in the ITN and regional trade patterns. |
Authors: | Matthew Smith |
Maintainer: | Matthew Smith <[email protected]> |
License: | GPL-3 |
Version: | 0.7.0 |
Built: | 2025-03-08 03:30:51 UTC |
Source: | https://github.com/cran/ITNr |
This takes a dataframe of node attributes and convert one into a absolute difference matrix
abs_diff_mat(DF, attrname)
abs_diff_mat(DF, attrname)
DF |
Dataframe of node attribute |
attrname |
names of the attribute from the dataframe to create the matrix for. |
Absolute difference matrix
Dataframe of capital city latitude and longitude coordinates
cap_lat_lon
cap_lat_lon
This function takes (import) trade data downloaded from comtrade - potentially using the comtradr package, cleans it and transforms it into a network. Adding a number of country level attributes to nodes in the network, including: regional partition, GDP, GDP per capita, GDP growth and FDI. However, it is important to note the limits of using comtradr to construct a network. Firstly when downloading the data with comtradr, you must specify reporters and partners – yet you cannot put “all” for both – only for either reporters or partners. Then for the other you are limited to a character vector of country names, length five or fewer. Therefore, this will not give you a full network. However, this function can be applied to trade data downloaded from UN Comtrade (download csv and read into R as a dataframe), or any other trade data. You just make sure it has the following column names: reporter_iso, partner_iso, trade_value_usd and year. Some dataformats may have different names. Also - it is important to note that this function is for import data.
Comtradrclean(DF, YEAR, threshold, cutoff)
Comtradrclean(DF, YEAR, threshold, cutoff)
DF |
Dataframe of trade data downloaded (potentially using the comtradr package) |
YEAR |
Year |
threshold |
Apply a threshold - TRUE, Extract the backbone - FALSE |
cutoff |
Threshold - cutoff level, Backbone - significance level |
International Trade Network - igraph object
This function implements rich club core-periphery algorithm (Ma & Mondragón, 2015) to identify members of the core and periphery in weighted networks
core_periphery_weighted(gs, type)
core_periphery_weighted(gs, type)
gs |
International Trade Network - igraph object. Note for networks not produced using ITNr there needs to be a vertex attribute "name" and edge attribute "weight" |
type |
directed/undirected |
List - 1.)igraph object with core-periphery results added as a node attribute. 2.) Dataframe of core-periphery results.
Ma A, Mondragón RJ (2015) Rich-Cores in Networks. PLoS ONE 10(3): e0119678. https://doi.org/10.1371/journal.pone.0119678
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Implement core-periphery algorithm ITNcp<-core_periphery_weighted(ITN,"directed")
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Implement core-periphery algorithm ITNcp<-core_periphery_weighted(ITN,"directed")
This function calculates the E-I Index (External-internal) at the group/attribute level
ei_group(gs, attrname)
ei_group(gs, attrname)
gs |
igraph object |
attrname |
Attribute name |
Group level results dataframe
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],15) ##Calculate the Group E-I Results EI_GROUP_DATAFRAME<-ei_group(gs,"letters")
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],15) ##Calculate the Group E-I Results EI_GROUP_DATAFRAME<-ei_group(gs,"letters")
This function calculates the E-I Index (External-internal) at the individual/node level
ei_ind(gs, attrname)
ei_ind(gs, attrname)
gs |
igraph object |
attrname |
Attribute name |
Group level results dataframe
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(30,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],6) ##Calculate the Individual E-I Results EI_IND_DATAFRAME<-ei_ind(gs,"letters")
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(30,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],6) ##Calculate the Individual E-I Results EI_IND_DATAFRAME<-ei_ind(gs,"letters")
This function calculates the E-I Index (External-internal) at the network level
ei_network(gs, attrname)
ei_network(gs, attrname)
gs |
igraph object |
attrname |
Attribute name |
Group level results dataframe
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],15) ##Calculate the Group E-I Results EI_NETWORK<-ei_network(gs,"letters")
require(igraph) ##Create random network (igraph object) gs<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(gs)$name<-1:vcount(gs) ## Add an attribute V(gs)$letters<- rep(LETTERS[1:5],15) ##Calculate the Group E-I Results EI_NETWORK<-ei_network(gs,"letters")
Electrical Automotive Goods 2016 Network. Electrical automotive goods category as defined by Amighini & Gogoni (2014)
ELEnet16
ELEnet16
Amighini, A. and Gorgoni, S. (2014) The International Reorganisation of Auto Production, The World Economy, 37(7), pp. 923–952.
List of Electrical Automotive Goods Networks for 2006 - 2016. Electrical automotive goods category as defined by Amighini & Gogoni (2014)
ELEnetList
ELEnetList
Amighini, A. and Gorgoni, S. (2014) The International Reorganisation of Auto Production, The World Economy, 37(7), pp. 923–952. (list of igraph objects)
This function extracts the backbone of a network
get.backbone(G, alpha, directed = TRUE)
get.backbone(G, alpha, directed = TRUE)
G |
igraph network |
alpha |
Significance level |
directed |
Default is TRUE |
Backbone of the network
Serrano, M. Á., Boguñá, M. and Vespignani, A. (2009) Extracting the multiscale backbone of complex weighted networks, Proceedings of the National Academy of Sciences, 106(16), pp. 6483–6488.
require(igraph) ##Create a random (directed) network gs<-erdos.renyi.game(50,0.2,directed = TRUE) ##Add edge weights to the network E(gs)$weight<-runif(ecount(gs), 0, 1) ##Extract backbone at 0.05 significance level backbone<-get.backbone(gs,0.1)
require(igraph) ##Create a random (directed) network gs<-erdos.renyi.game(50,0.2,directed = TRUE) ##Add edge weights to the network E(gs)$weight<-runif(ecount(gs), 0, 1) ##Extract backbone at 0.05 significance level backbone<-get.backbone(gs,0.1)
This function check whether data is numeric(0) and give returns an NA if this is true and the value of the data otherwise.
isEmpty(x)
isEmpty(x)
x |
Data |
NA or the data
This function plots a single/clean ITN
ITN_make_plot(gs, LABEL, REGION)
ITN_make_plot(gs, LABEL, REGION)
gs |
International Trade Network - igraph object |
LABEL |
Should labels be present - TRUE/FALSE |
REGION |
Should nodes be coloured on the basis of region TRUE/FALSE |
Panel of ITN plots
##Load graph data("ELEnet16") ##Otherwise download data from WITS and create an ##International Trade Network using WITSclean() ##Plot the network - No Label, colour by region ITN_plot_example<-ITN_make_plot(ELEnet16,FALSE,TRUE)
##Load graph data("ELEnet16") ##Otherwise download data from WITS and create an ##International Trade Network using WITSclean() ##Plot the network - No Label, colour by region ITN_plot_example<-ITN_make_plot(ELEnet16,FALSE,TRUE)
This function plots the international trade network on a world map
ITN_map_plot(gs)
ITN_map_plot(gs)
gs |
International Trade Network - igraph object |
Plot of the ITN on world map
require(maps) ##Load the ITN data(ELEnet16) ## Plot ITN on map - node size based on outdegree ITN_map_plot(ELEnet16)
require(maps) ##Load the ITN data(ELEnet16) ## Plot ITN on map - node size based on outdegree ITN_map_plot(ELEnet16)
This function adjusts ITN matrices so they are the same size
ITNadjust(MATlist, j)
ITNadjust(MATlist, j)
MATlist |
A list of ITN matrices |
j |
Element of matrix list to compare with others |
Matrix
##Create a list of random matrices (of different sizes) ##Labels - letters of alphabet (can represent actor names) mat1<- matrix(round(runif(10*10)), 10, 10) rownames(mat1)<-LETTERS[1:10] colnames(mat1)<-LETTERS[1:10] mat2<- matrix(round(runif(10*10)), 10, 10) rownames(mat2)<-LETTERS[10:19] colnames(mat2)<-LETTERS[10:19] mat3<- matrix(round(runif(12*12)), 12, 12) rownames(mat3)<-LETTERS[15:26] colnames(mat3)<-LETTERS[15:26] ##Create matrix list MATlist<-list(mat1,mat2,mat3) ##Adjust matrix 1 so that it has additional rows/actors not ##in the original matrix mat1adjust<-ITNadjust(MATlist,1)
##Create a list of random matrices (of different sizes) ##Labels - letters of alphabet (can represent actor names) mat1<- matrix(round(runif(10*10)), 10, 10) rownames(mat1)<-LETTERS[1:10] colnames(mat1)<-LETTERS[1:10] mat2<- matrix(round(runif(10*10)), 10, 10) rownames(mat2)<-LETTERS[10:19] colnames(mat2)<-LETTERS[10:19] mat3<- matrix(round(runif(12*12)), 12, 12) rownames(mat3)<-LETTERS[15:26] colnames(mat3)<-LETTERS[15:26] ##Create matrix list MATlist<-list(mat1,mat2,mat3) ##Adjust matrix 1 so that it has additional rows/actors not ##in the original matrix mat1adjust<-ITNadjust(MATlist,1)
This function calculates block membership for the ITN and then plots the network, with node colour according to block membership.
ITNblock_plot(gs, LABEL)
ITNblock_plot(gs, LABEL)
gs |
International Trade Network - igraph object |
LABEL |
Should labels be present - TRUE/FALSE |
Network Plot - nodes coloured based on block membership
require(igraph) require(sna) require(intergraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Blockmodel plot block_plot<-ITNblock_plot(ITN,FALSE)
require(igraph) require(sna) require(intergraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Blockmodel plot block_plot<-ITNblock_plot(ITN,FALSE)
This function calculates block membership for ITN and structural equivalence between countries
ITNblock_se(gs)
ITNblock_se(gs)
gs |
International Trade Network - igraph object |
List object containing block membership and structural equivalence matrix results
require(igraph) require(sna) require(intergraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Blockmodel & structural equivalence analysis blockse<-ITNblock_se(ITN)
require(igraph) require(sna) require(intergraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Blockmodel & structural equivalence analysis blockse<-ITNblock_se(ITN)
This function calculates a number of centrality metrics for the weighted International Trade Network (ITN)
ITNcentrality(gs)
ITNcentrality(gs)
gs |
International Trade Network - igraph object |
Table of centrality results (dataframe)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Calculate the centrality measures ITNCENT<-ITNcentrality(ITN)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Calculate the centrality measures ITNCENT<-ITNcentrality(ITN)
This function calculates a number of centrality metrics for the binary International Trade Network (ITN)
ITNcentrality_binary(gs)
ITNcentrality_binary(gs)
gs |
International Trade Network - binary igraph object |
Table of centrality results (dataframe)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Calculate the centrality measures ITNCENT<-ITNcentrality_binary(ITN)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add vertex names V(ITN)$name<-1:vcount(ITN) ##Calculate the centrality measures ITNCENT<-ITNcentrality_binary(ITN)
This function calculates cluster membership for ITN
ITNcluster(gs)
ITNcluster(gs)
gs |
International Trade Network - igraph object (with region attribute) |
Cluster object containing various cluster membership results
##Load ITN data(ELEnet16) ##Cluster Analysis CLU<-ITNcluster(ELEnet16)
##Load ITN data(ELEnet16) ##Cluster Analysis CLU<-ITNcluster(ELEnet16)
This function plots the correlation between degree and strength scores
ITNcorr(gs)
ITNcorr(gs)
gs |
International Trade Network - igraph object |
Correlation plot
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot correlation matrix between degree and strength scores. corr_plot<-ITNcorr(ITN)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot correlation matrix between degree and strength scores. corr_plot<-ITNcorr(ITN)
This function plots the ITN (probability) degree distribtuion
ITNdegdist(gs)
ITNdegdist(gs)
gs |
International Trade Network - igraph object |
Panel of ITN degree distribution plots
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Plot degree distribution deg_dist_plot<-ITNdegdist(ITN)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Plot degree distribution deg_dist_plot<-ITNdegdist(ITN)
This function produces a dynamic network object for ITNs. It cleans and adjusts the individual networks, so they are the same size. This dynamic network object can then be used to create animations, mapping changes over time and to calculate temporal network statistics
ITNdynamic(NETlist)
ITNdynamic(NETlist)
NETlist |
A list of International Trade Networks (igraph objects) |
It returns the Dynamic Network Object
require(igraph) ##Create a set of random International Trade Networks (igraph objects) ##and add vertex names ITN1<-erdos.renyi.game(75,0.05,directed = TRUE) V(ITN1)$name<-1:vcount(ITN1) ITN2<-erdos.renyi.game(100,0.01,directed = TRUE) V(ITN2)$name<-1:vcount(ITN2) ITN3<-erdos.renyi.game(55,0.1,directed = TRUE) V(ITN3)$name<-1:vcount(ITN3) ##Create network list NETlist<-list(ITN1,ITN2,ITN3) ##Create Dynamic Network Object ITNdyn<-ITNdynamic(NETlist)
require(igraph) ##Create a set of random International Trade Networks (igraph objects) ##and add vertex names ITN1<-erdos.renyi.game(75,0.05,directed = TRUE) V(ITN1)$name<-1:vcount(ITN1) ITN2<-erdos.renyi.game(100,0.01,directed = TRUE) V(ITN2)$name<-1:vcount(ITN2) ITN3<-erdos.renyi.game(55,0.1,directed = TRUE) V(ITN3)$name<-1:vcount(ITN3) ##Create network list NETlist<-list(ITN1,ITN2,ITN3) ##Create Dynamic Network Object ITNdyn<-ITNdynamic(NETlist)
This function plots the histogram degree distribution for the ITN
ITNhistdegdist(gs)
ITNhistdegdist(gs)
gs |
International Trade Network - igraph object |
Panel of ITN histogram degree distribution plots
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot degree distribution histogram hist_deg_dist<-ITNhistdegdist(ITN)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot degree distribution histogram hist_deg_dist<-ITNhistdegdist(ITN)
The following function produces a plot showing imports (in degree) vs exports (out degree). This allows us to identify whether in the ITN, countries that export high levels also import high levels. The plot can be produced for either weighted or binary import and export ties.
ITNimvex(gs, weighted)
ITNimvex(gs, weighted)
gs |
International Trade Network - igraph object |
weighted |
TRUE - plot import strength vs export strength. FALSE - Import count Vs export count |
Imports Vs Exports Plot
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot binary import vs exports imvex_plot<-ITNimvex(ITN,FALSE)
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Add edge weights E(ITN)$weight<-runif(ecount(ITN), 0, 1) ##Plot binary import vs exports imvex_plot<-ITNimvex(ITN,FALSE)
This function creates a panel of four plots of the ITN for a quick inspection. These include plots: (i) highlighting clusters using the fast greedy algorithm.(ii)node colours for communities detected using the spinglass algorithm. (iii)nodes coloured by regional partition and (iv)with nodes coloured by regional partition and node size based on outdegree centrality.
ITNplotset(gs)
ITNplotset(gs)
gs |
International Trade Network - igraph object |
Panel of ITN plots
##Load the network data(ELEnet16) ##Plot set of network visualisations ITNplotset(ELEnet16)
##Load the network data(ELEnet16) ##Plot set of network visualisations ITNplotset(ELEnet16)
This function calculates network level properties for the ITN. These include: -Size (number of nodes) -Density -Reciprocity -Diameter -Average path length -Average node strength -Average Degree -Betweenness Centralisation -Closeness Centralisation -Eigenvector Centralisation -Out Degree Centralisation -In Degree Centralisation -All Degree Centralisation -Clustering coefficent (transitivity) -Clustering Weighted -Region Homophily -Degree Assortativity
ITNproperties(gs, weighted)
ITNproperties(gs, weighted)
gs |
International Trade Network - igraph object |
weighted |
TRUE-weighted, FALSE-binary |
Table of centrality results (dataframe)
##Load the network data(ELEnet16) ##Calculate the network properties ITNPROP<-ITNproperties(ELEnet16,TRUE)
##Load the network data(ELEnet16) ##Calculate the network properties ITNPROP<-ITNproperties(ELEnet16,TRUE)
This function calculates network level properties for the ITN. These include: -Size (number of nodes) -Density -Reciprocity -Diameter -Average path length -Average node strength -Average Degree -Betweenness Centralisation -Closeness Centralisation -Eigenvector Centralisation -Out Degree Centralisation -In Degree Centralisation -All Degree Centralisation -Clustering coefficent (transitivity) -Clustering Weighted -Degree Assortativity
ITNproperties_base(gs, weighted)
ITNproperties_base(gs, weighted)
gs |
International Trade Network - igraph object |
weighted |
TRUE-weighted, FALSE-binary |
Table of centrality results (dataframe)
##Load the network data(ELEnet16) ##Calculate the network properties ITNPROP<-ITNproperties_base(ELEnet16,TRUE)
##Load the network data(ELEnet16) ##Calculate the network properties ITNPROP<-ITNproperties_base(ELEnet16,TRUE)
This function takes (import) trade data and cleans it and transforms it into a network. This function can be applied to trade data downloaded from UN Comtrade (download csv and read into R as a dataframe), or any other trade data. You just make sure it has the following column names: reporter_iso, partner_iso and edge_weight. Some dataformats may have different names. Also - it is important to note that this function is for import data.
make_trade_network(DF, threshold, cutoff)
make_trade_network(DF, threshold, cutoff)
DF |
Dataframe of trade data downloaded (potentially using the comtradr package) |
threshold |
Apply a threshold - TRUE, Extract the backbone - FALSE |
cutoff |
Threshold - cutoff level, Backbone - significance level |
International Trade Network - igraph object
This function calculates the mixing matrix for an igraph object
mixing_matrix_igraph(gs, attrname)
mixing_matrix_igraph(gs, attrname)
gs |
igraph object. |
attrname |
Attribute name (vertex attribute) |
Mixing matrix
require(igraph) ##Create random International Trade Network (igraph object) gs<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add vertex attributes V(gs)$LETTER<-rep(LETTERS[1:5],10) ##Add vertex names V(gs)$name<-1:vcount(gs) ##Calculate mixing matrix mixing_matrix<-mixing_matrix_igraph(gs,"LETTER")
require(igraph) ##Create random International Trade Network (igraph object) gs<-erdos.renyi.game(50,0.05,directed = TRUE) ##Add vertex attributes V(gs)$LETTER<-rep(LETTERS[1:5],10) ##Add vertex names V(gs)$name<-1:vcount(gs) ##Calculate mixing matrix mixing_matrix<-mixing_matrix_igraph(gs,"LETTER")
This function plots degree distribution for any graph
plot_degree_distribution(graph, a)
plot_degree_distribution(graph, a)
graph |
igraph object |
a |
mode - "in","out","all |
Panel of ITN degree distribution plots
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Plot out degree distribution plot_degree_distribution(ITN,"in")
require(igraph) ##Create random International Trade Network (igraph object) ITN<-erdos.renyi.game(75,0.05,directed = TRUE) ##Plot out degree distribution plot_degree_distribution(ITN,"in")
This takes a dataframe of node attributes and convert one into a matrix of receiver attributes
receiver_mat(DF, attrname)
receiver_mat(DF, attrname)
DF |
Dataframe of node attribute |
attrname |
names of the attribute from the dataframe to create the matrix for. |
Receiver matrix
This function creates a chord diagram/circle plot for levels of trade between regional partitions
region_circle_plot(gs)
region_circle_plot(gs)
gs |
igraph ITN object (with attributes added) |
Circle Plot
##Load graph data("ELEnet16") ##Create region circle plot region_circle_plot(ELEnet16)
##Load graph data("ELEnet16") ##Create region circle plot region_circle_plot(ELEnet16)
Reorders the rows of one dataframe according to another vector (id vector)
reorder_df(df, col_sort, reorder_data)
reorder_df(df, col_sort, reorder_data)
df |
dataframe to reorder |
col_sort |
column on which the rows will be reordered |
reorder_data |
vector with the new order |
Reordered dataframe
df <- data.frame(a = letters[1:3],b = LETTERS[4:6],c = 7:9) reorder_data<-c("c","a","b") df_new<-reorder_df(df,"a",reorder_data) df_new
df <- data.frame(a = letters[1:3],b = LETTERS[4:6],c = 7:9) reorder_data<-c("c","a","b") df_new<-reorder_df(df,"a",reorder_data) df_new
This function rounds the numeric variables in a dataframe containing numeric and non-numeric data
round_df(x, digits)
round_df(x, digits)
x |
dataframe |
digits |
digits to round to |
Dataframe with rounded numbers
##Create dataframe ID = c("a","b","c","d","e") Value1 = c(3.445662,6.44566,8.75551,1.114522,1.5551) Value2 = c(8.2,1.7,6.4,19.45459,10.34524) df<-data.frame(ID,Value1,Value2) ##Round to 2 digits rounddf<-round_df(df,2)
##Create dataframe ID = c("a","b","c","d","e") Value1 = c(3.445662,6.44566,8.75551,1.114522,1.5551) Value2 = c(8.2,1.7,6.4,19.45459,10.34524) df<-data.frame(ID,Value1,Value2) ##Round to 2 digits rounddf<-round_df(df,2)
This takes a dataframe of node attributes and convert one into a matrix of sender attributes
sender_mat(DF, attrname)
sender_mat(DF, attrname)
DF |
Dataframe of node attribute |
attrname |
names of the attribute from the dataframe to create the matrix for. |
Sender matrix
This function takes (import) trade data downloaded from WITS, cleans it and transforms it into a network. Adding a number of country level attributes to nodes in the network, including: regional partition, GDP, GDP per capita, GDP growth and FDI.
WITSclean(CSVfile, YEAR, threshold, cutoff)
WITSclean(CSVfile, YEAR, threshold, cutoff)
CSVfile |
WITS csv file |
YEAR |
Year |
threshold |
Apply a threshold - TRUE, Extract the backbone - FALSE |
cutoff |
Threshold - cutoff level, Backbone - significance level |
International Trade Network - igraph object