Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ Theme fixes:
- Model-fit and various distribution types gain a `weights` argument; although
this is best provided from the top-level `tinyplot()`/`plt()` call. See
above.
- `legend = list(title = FALSE)` now suppresses the legend title, matching the
existing `title = NULL` behaviour. (#653 @grantmcdermott)

### Bug fixes

Expand Down
2 changes: 2 additions & 0 deletions R/legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ build_legend_args = function(

# Set defaults
if (!exists("title", where = legend_args)) legend_args[["title"]] = by_dep
# Treat title = FALSE the same as NULL, i.e. suppress the title (#652).
if (isFALSE(legend_args[["title"]])) legend_args[["title"]] = NULL
legend_args[["pch"]] = legend_args[["pch"]] %||% pch
legend_args[["lty"]] = legend_args[["lty"]] %||% lty
legend_args[["col"]] = legend_args[["col"]] %||% col
Expand Down
4 changes: 3 additions & 1 deletion R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@
#' effect as specifying NULL) and FALSE turns the legend off (same effect as
#' specifying "none").
#' - A list or, equivalently, a dedicated `legend()` function with supported
#' legend arguments, e.g. "bty", "horiz", and so forth.
#' legend arguments, e.g. "bty", "horiz", and so forth. To suppress the
#' legend title, set `title = NULL` or `title = FALSE`, e.g.
#' `legend = list(title = FALSE)`.
#' @param main a main title for the plot, see also `title`.
#' @param sub a subtitle for the plot.
#' @param cap a caption for the plot, drawn at the bottom. Useful for
Expand Down
7 changes: 7 additions & 0 deletions inst/tinytest/test-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ f = function() tinyplot(
)
expect_snapshot_plot(f, label = "legend_title_null")

# title = FALSE should suppress the title, just like title = NULL (#652)
f = function() tinyplot(
Temp ~ Day | Month, data = aq,
legend = list(title = FALSE)
)
expect_snapshot_plot(f, label = "legend_title_null")

f = function() tinyplot(
Temp ~ Day | Month, data = aq,
legend = legend(legend = month.abb[5:9])
Expand Down
4 changes: 3 additions & 1 deletion man/tinyplot.Rd

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

2 changes: 1 addition & 1 deletion vignettes/gallery_figs/ellipse-penguins.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plt(
main = 'A waddle of penguins',
sub = 'Species stick together',
theme = 'web',
legend = list('top!', title = NULL)
legend = list('top!', title = FALSE)
)
plt_add(type = 'ellipse', fill = 0.1)
# plt_add(type = 'chull', fill = 0.1, col = NA) ## another option
2 changes: 1 addition & 1 deletion vignettes/gallery_figs/likert.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plt(
share ~ question | response, data = lik,
type = "barplot", center = TRUE, offset = "Unsure",
flip = TRUE, xlab = NA, ylab = NA, yaxl = "percent",
legend = list("top!", title = NULL),
legend = list("top!", title = FALSE),
theme = list("clean2", palette.qualitative = pal),
main = "Likert example with \"Unsure\" category offset"
)
Expand Down