diff --git a/R/messages.R b/R/messages.R index c75afa95..ba16795f 100644 --- a/R/messages.R +++ b/R/messages.R @@ -45,4 +45,13 @@ message_nothing_to_show = function(any_groups) { } else { message("[nothing to show] no layers defined") } -} \ No newline at end of file +} + +message_wrapstack = function(horizontal = TRUE) { + if (horizontal) { + message("[facets] use tm_facets_hstack() instead of tm_facets_wrap() to put the legends next to and aligned with the facets") + } else { + message("[facets] use tm_facets_vstack() instead of tm_facets_wrap() to put the legends next to and aligned with the facets") + } + +} diff --git a/R/process_meta.R b/R/process_meta.R index ea75b429..529a75cf 100644 --- a/R/process_meta.R +++ b/R/process_meta.R @@ -74,12 +74,17 @@ preprocess_meta = function(o, cdt) { # in case there are per-facet legends but no no marginal legends, and nrows or ncols equals 1, place them outside (to do this, set them to all-facet here, change legend.position.all below accordingly, and finally determine legend position in step4_plot) - if (legend.present.auto[4] && (!any(legend.present.auto[2:3])) && (type == "stack")) { - per_facet_wrap_outside = TRUE - legend.present.auto[1] = TRUE - legend.present.auto[4] = FALSE + if (legend.present.auto[4] && (!any(legend.present.auto[2:3]))) { + + if (type == "stack") { + legend.present.auto[1] = TRUE + legend.present.auto[4] = FALSE + set_to_stack_message = FALSE + } else { + set_to_stack_message = TRUE + } } else { - per_facet_wrap_outside = FALSE + set_to_stack_message = FALSE } @@ -510,6 +515,7 @@ process_meta = function(o, d, cdt, aux) { nrows = ceiling(n / ncols) } + if ((nrows == 1 || ncols == 1) && set_to_stack_message) message_wrapstack(nrows == 1) } #overall scale down factor for facets diff --git a/R/step4_plot.R b/R/step4_plot.R index 647143bb..5b00493c 100644 --- a/R/step4_plot.R +++ b/R/step4_plot.R @@ -213,7 +213,7 @@ step4_plot = function(tm, vp, return.asp, show, knit, args) { aux = tm$aux cmp = tm$cmp - if ("bbx" %in% names(tmx[[o$main]])) { + if (length(tmx) && ("bbx" %in% names(tmx[[o$main]]))) { bbm = tmx[[o$main]]$bbx } else { bbm = NULL