This function prepares input data for geom_asymmat() by adding in any missing comparisons to be plotted. Note that this function observes groups created with the dplyr::group_by() function. For the 'ggasym' package, this is useful for when you want to facet the plot: before "asymmetrizing" the data table, use dplyr::group_by(), passing the column name you wish to later facet by. This functionality is demonstrated in the second example, below.

asymmetrise(df, .x, .y)

asymmetrize(df, .x, .y)

Arguments

df

a tidy data.frame or tibble

.x, .y

the data to add all comparisons between (ie. will be the x and y-axes for geom_asymmat()

Value

a data table with new rows for the added comparisons

Warning

This function does it's best when x or y are factors. If they have the same levels, then they are maintained. If the levels partially overlap, they are merged. Otherwise, the values are turned into characters and all levels dropped. If you are using factors, save yourself the headache and make both columns factors with the desired levels.

Examples

df <- data.frame( a = c("A", "B", "C"), b = c("C", "A", "B"), untouched = c(1, 2, 3), grouping_value = c("group1", "group1", "group2"), stringsAsFactors = FALSE ) df
#> a b untouched grouping_value #> 1 A C 1 group1 #> 2 B A 2 group1 #> 3 C B 3 group2
asymmetrise(df, a, b)
#> a b untouched grouping_value #> 1 A C 1 group1 #> 2 B A 2 group1 #> 3 C B 3 group2 #> 4 C A 1 group1 #> 5 A B 2 group1 #> 6 B C 3 group2 #> 7 A A NA <NA> #> 8 B B NA <NA> #> 9 C C NA <NA>
grouped_df <- dplyr::group_by(df, grouping_value) asymmetrise(grouped_df, a, b)
#> # A tibble: 13 x 4 #> # Groups: grouping_value [2] #> grouping_value a b untouched #> <chr> <chr> <chr> <dbl> #> 1 group1 A C 1 #> 2 group1 B A 2 #> 3 group1 C A 1 #> 4 group1 A B 2 #> 5 group1 A A NA #> 6 group1 B B NA #> 7 group1 C B NA #> 8 group1 B C NA #> 9 group1 C C NA #> 10 group2 C B 3 #> 11 group2 B C 3 #> 12 group2 C C NA #> 13 group2 B B NA