Load the data:
wine.df = read.csv("~/Mat/wine_trade.csv", header = TRUE, stringsAsFactors = FALSE)
Arrange and subset the data to have only top exporters:
wineEx.df = subset(wine.df, subset = type == "Export", c("reporting_country",
"partner_country", "Wine"))
wineEx.df = arrange(wineEx.df, desc(Wine))
wineEx.df$sWine = scale(wineEx.df$Wine, center = FALSE)
wineEx.df$cs = cumsum(wineEx.df$Wine)
wineEx.df[wineEx.df[, 1] == "China, Hong Kong SAR ", 1] = "China, Hong Kong SAR"
wineFinal.df = subset(wineEx.df, cs < tail(wineEx.df$cs, 1) * 0.8)
Let us inspect that data:
head(wineFinal.df)
## reporting_country partner_country Wine sWine cs
## 1 France United Kingdom 1521136 27.66 1521136
## 2 Italy Germany 1120728 20.38 2641864
## 3 Italy United States of America 1086661 19.76 3728525
## 4 France United States of America 983264 17.88 4711789
## 5 France Germany 850024 15.45 5561813
## 6 France Belgium 725637 13.19 6287450
Set size of nodes:
## Set edge and arrow size
wineFinal.df$edgeSize = with(wineFinal.df, Wine/sum(Wine))
wineFinal.df$arrowSize = ifelse(wineFinal.df$edgeSize * 30 < 0.5, 0.5, wineFinal.df$edgeSize *
30)
## Create the network and plot
wine.net = network(wineFinal.df[, 1:2])
plot(wine.net, displaylabels = TRUE, label.col = "steelblue", edge.lwd = c(wineFinal.df$edgeSize) *
100, arrowhead.cex = c(wineFinal.df$arrowSize), label.cex = 0.5, vertex.border = "white",
vertex.col = "skyblue", edge.col = rgb(0, 0, 0, alpha = 0.5))