Skip to content

Commit

Permalink
Merge pull request #31 from gernophil/master
Browse files Browse the repository at this point in the history
added option to use geom_text instead of geom_label
  • Loading branch information
erblast authored Dec 7, 2023
2 parents 34d419a + 6f1c755 commit 0993abb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
11 changes: 9 additions & 2 deletions R/alluvial_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#' Default:RColorBrewer::brewer.pal(9, 'Greys')[c(3,6,4,7,5)]
#'@param verbose logical, print plot summary, Default: F
#'@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 @@ -116,6 +117,7 @@ alluvial_long = function( data
, col_vector_value = RColorBrewer::brewer.pal(9, 'Greys')[c(3,6,4,7,5)]
, verbose = F
, stratum_labels = T
, stratum_label_type = "label"
, stratum_label_size = 4.5
, stratum_width = 1/4
, auto_rotate_xlabs = T
Expand Down Expand Up @@ -435,8 +437,13 @@ alluvial_long = function( data
labs( x = '', y = 'count', caption = caption)

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


Expand Down
11 changes: 9 additions & 2 deletions R/alluvial_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if(getRversion() >= "2.15.1"){
#' fill variable stratum, Default: TRUE
#'@param verbose logical, print plot summary, Default: F
#'@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 @@ -98,6 +99,7 @@ alluvial_wide = function( data
, colorful_fill_variable_stratum = T
, verbose = F
, stratum_labels = T
, stratum_label_type = "label"
, stratum_label_size = 4.5
, stratum_width = 1/4
, auto_rotate_xlabs = T
Expand Down Expand Up @@ -367,8 +369,13 @@ alluvial_wide = function( data
labs( x = '', y = 'count', caption = caption)

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

# angle x labels------------------------------------
Expand Down
1 change: 1 addition & 0 deletions inst/logo/logo.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ p = alluvial_long(monthly_flights, key = qu, value = mean_arr_delay, fill = car
, col_vector_flow = col
, col_vector_value = c('#666633', '#999966')
, stratum_labels = F
, stratum_label_type = "label"
, stratum_width = 1/4 ) +
labs( caption = '') +
theme_minimal() +
Expand Down
3 changes: 3 additions & 0 deletions man/alluvial_long.Rd

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

3 changes: 3 additions & 0 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 = FALSE, 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
1 change: 1 addition & 0 deletions tests/testthat/test_alluvial_wide.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test_that('alluvial_wide'
, max_variables = max_variables
, fill_by = 'first_variable'
, 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 0993abb

Please sign in to comment.