You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R/plot_sankey.R
+27-13Lines changed: 27 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,8 @@
3
3
#' A function to create a Sankey plot showcasing elements of seafood supply chains in ARTIS or consumption datasets.
4
4
#'
5
5
#' @param data dataframe. An ARTIS trade or consumption dataframe.
6
-
#' @param cols vector. Column names to generate the sections of the Sankey plot, in the order they should appear (left to right).
6
+
#' @param cols character vector. Column names to generate the sections of the Sankey plot, in the order they should appear (left to right).
7
+
#' @param cols_labels character vector. User-specified labels for the columns selected with cols argument.
7
8
#' @param prop_flow_cutoff integer. A percent in which trade volumes that comprise less than x\% of the total trade are renamed as "Other". Default prop_flow_cutoff = 0.05 means trade volumes less than 5\% are labeled as "Other".
8
9
#' @param value character. Trade quantity column name to visualize. Default is "live_weight_t".
9
10
#' @param show.other logical. Controls whether or not nodes within a column falling below the prop_flow_cutoff threshold should be displayed in a group ("Other"). Default value is TRUE, filtering for threshold occurs regardless if "Other" is displayed.
@@ -33,6 +34,9 @@ plot_sankey <- function(data,
33
34
cols= c("source_country_iso3c",
34
35
"exporter_iso3c",
35
36
"importer_iso3c"),
37
+
cols_labels= c("Source",
38
+
"Exporter",
39
+
"Importer"),
36
40
prop_flow_cutoff=0.05,
37
41
value="live_weight_t",
38
42
show.other=TRUE,
@@ -43,24 +47,32 @@ plot_sankey <- function(data,
43
47
warning("WARNING: The selected columns include NA values")
44
48
}
45
49
46
-
# Setting up parameters based on user input-----------------------------------
50
+
if(length(cols) != length(cols_labels)){
51
+
stop("cols and cols_labels must be the same length")
52
+
}
47
53
48
-
# Assign weight column to quantity
49
-
quantity<-value
54
+
# Setting up parameters based on user input-----------------------------------
50
55
51
-
# Summarizing data based on quantity variable selected
56
+
# Summarizing data based on value variable selected
0 commit comments