Skip to content

Commit

Permalink
added stratum_label_type to select label or text
Browse files Browse the repository at this point in the history
  • Loading branch information
gernophil committed Nov 19, 2023
1 parent 93530db commit 20b7fc3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
20 changes: 12 additions & 8 deletions R/alluvial_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#'@param col_vector_value HEX color values for y levels/values,
#' Default:RColorBrewer::brewer.pal(9, 'Greys')[c(3,6,4,7,5)]
#'@param verbose logical, print plot summary, Default: F
#'@param stratum_labels character, Default: "label"
#'@param stratum_labels logical, Default: TRUE
#'@param stratum_label_type character, Default: "label"
#'@param stratum_label_size numeric, Default: 4.5
#'@param stratum_width double, Default: 1/4
#'@param auto_rotate_xlabs logical, Default: TRUE
Expand Down Expand Up @@ -115,7 +116,8 @@ alluvial_long = function( data
, col_vector_flow = palette_qualitative() %>% palette_filter( greys = F)
, col_vector_value = RColorBrewer::brewer.pal(9, 'Greys')[c(3,6,4,7,5)]
, verbose = F
, stratum_labels = "label"
, stratum_labels = T
, stratum_label_type = "label"
, stratum_label_size = 4.5
, stratum_width = 1/4
, auto_rotate_xlabs = T
Expand Down Expand Up @@ -434,12 +436,14 @@ alluvial_long = function( data
scale_color_identity() +
labs( x = '', y = 'count', caption = caption)

if(stratum_labels == "label"){
p = p + geom_label( stat = ggalluvial::StatStratum
, size = stratum_label_size )
} else if (stratum_labels == "text"){
p = p + geom_text( stat = ggalluvial::StatStratum
, size = stratum_label_size )
if(stratum_labels){
if(stratum_label_type == "label"){
p = p + geom_label( stat = ggalluvial::StatStratum
, size = stratum_label_size )
} else if (stratum_labels == "text"){
p = p + geom_text( stat = ggalluvial::StatStratum
, size = stratum_label_size )
}
}


Expand Down
20 changes: 12 additions & 8 deletions R/alluvial_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ if(getRversion() >= "2.15.1"){
#'@param colorful_fill_variable_stratum logical, use flow colors to colorize
#' fill variable stratum, Default: TRUE
#'@param verbose logical, print plot summary, Default: F
#'@param stratum_labels character, Default: "label"
#'@param stratum_labels logical, Default: TRUE
#'@param stratum_label_type character, Default: "label"
#'@param stratum_label_size numeric, Default: 4.5
#'@param stratum_width double, Default: 1/4
#'@param auto_rotate_xlabs logical, Default: TRUE
Expand Down Expand Up @@ -97,7 +98,8 @@ alluvial_wide = function( data
, col_vector_value = RColorBrewer::brewer.pal(9, 'Greys')[c(4,7,5,8,6)]
, colorful_fill_variable_stratum = T
, verbose = F
, stratum_labels = "label"
, stratum_labels = T
, stratum_label_type = "label"
, stratum_label_size = 4.5
, stratum_width = 1/4
, auto_rotate_xlabs = T
Expand Down Expand Up @@ -366,12 +368,14 @@ alluvial_wide = function( data
scale_color_identity() +
labs( x = '', y = 'count', caption = caption)

if(stratum_labels == "label"){
p = p + geom_label( stat = ggalluvial::StatStratum
, size = stratum_label_size )
} else if (stratum_labels == "text"){
p = p + geom_text( stat = ggalluvial::StatStratum
, size = stratum_label_size )
if(stratum_labels){
if(stratum_label_type == "label"){
p = p + geom_label( stat = ggalluvial::StatStratum
, size = stratum_label_size )
} else if (stratum_labels == "text"){
p = p + geom_text( stat = ggalluvial::StatStratum
, size = stratum_label_size )
}
}

# angle x labels------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion inst/logo/logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ col = viridisLite::inferno(12)
p = alluvial_long(monthly_flights, key = qu, value = mean_arr_delay, fill = carrier, id = flight_id
, col_vector_flow = col
, col_vector_value = c('#666633', '#999966')
, stratum_labels = "label"
, stratum_labels = F
, stratum_label_type = "label"
, stratum_width = 1/4 ) +
labs( caption = '') +
theme_minimal() +
Expand Down
7 changes: 5 additions & 2 deletions man/alluvial_long.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/alluvial_wide.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test_alluvial_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test_that('alluvial_long'
# check stratum options

p = alluvial_long( data, key = qu, value = mean_arr_delay, id = tailnum, fill = carrier
, stratum_labels = "none", stratum_width = 1/20)
, stratum_labels = FALSE, stratum_label_type = "none", stratum_width = 1/20)

# comes up as false positive try again with next vdiffr version
#expect_doppelganger('long_strat_width', p)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test_alluvial_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ test_that('alluvial_wide'
p = alluvial_wide( data = data
, max_variables = max_variables
, fill_by = 'first_variable'
, stratum_labels = "none"
, stratum_labels = F
, stratum_label_type = "none"
, stratum_width = 1/20 )

#vdiffr detects difference when rendered with different OS
Expand Down

0 comments on commit 20b7fc3

Please sign in to comment.