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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinyplot
Type: Package
Title: Lightweight Extension of the Base R Graphics System
Version: 0.0.5.9007
Version: 0.0.5.9008
Authors@R:
c(
person(
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# News

## 0.0.5.9007 (development version)
## 0.0.5.9008 (development version)

License:

Expand Down Expand Up @@ -39,6 +39,8 @@ Bug fixes:

- Fixed bug that prevented `tpar(facet.x = ...)` args from being passed forward
and set correctly. (#137 @grantmcdermott)
- Fixed bug where custom legends weren't working with `type = "density"`. (#147
@grantmcdermott)

Internals:

Expand Down
38 changes: 20 additions & 18 deletions R/draw_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,28 @@ draw_legend = function(
#
## legend args ----

if (is.null(legend)) {
legend_args[["x"]] = "right!"
} else if (is.character(legend)) {
legend_args = utils::modifyList(legend_args, list(x = legend))
} else if (class(legend) %in% c("call", "name")) {
largs = as.list(legend)
if (is.null(largs[["x"]])) {
lnms = names(largs)
# check second position b/c first will be a symbol
if (is.null(lnms)) {
largs = stats::setNames(largs, c("", "x"))
} else if (length(largs)>=2 && lnms[2] == "") {
lnms[2] = "x"
largs = stats::setNames(largs, lnms)
} else {
largs[["x"]] = "right!"
if (is.null(legend_args[["x"]])) {
if (is.null(legend)) {
legend_args[["x"]] = "right!"
} else if (is.character(legend)) {
legend_args = utils::modifyList(legend_args, list(x = legend))
} else if (class(legend) %in% c("call", "name")) {
largs = as.list(legend)
if (is.null(largs[["x"]])) {
lnms = names(largs)
# check second position b/c first will be a symbol
if (is.null(lnms)) {
largs = stats::setNames(largs, c("", "x"))
} else if (length(largs)>=2 && lnms[2] == "") {
lnms[2] = "x"
largs = stats::setNames(largs, lnms)
} else {
largs[["x"]] = "right!"
}
}
# Finally, combine with any pre-existing legend args (e.g., title from the by label)
legend_args = utils::modifyList(legend_args, largs, keep.null = TRUE)
}
# Finally, combine with any pre-existing legend args (e.g., title from the by label)
legend_args = utils::modifyList(legend_args, largs, keep.null = TRUE)
}

## Use `!exists` rather than `is.null` for title in case user specified no title
Expand Down
11 changes: 9 additions & 2 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,15 @@ tinyplot.default = function(
}
## Another catch for bespoke legend position (if originally passed via the formula method)
if (!is.null(fargs[["legend"]]) && !is.null(fargs[["legend_args"]])) {
if (names(fargs[["legend"]])[1] == "") names(fargs[["legend"]])[1] = "x"
fargs[["legend_args"]] = utils::modifyList(fargs[["legend"]], fargs[["legend_args"]])
if (is.atomic(fargs[["legend"]])) {
fargs[["legend"]] = list(x = fargs[["legend"]])
} else if (!is.list(fargs[["legend"]])) {
fargs[["legend"]] = as.list(fargs[["legend"]])
}
if (is.null(names(fargs[["legend"]])[1]) || names(fargs[["legend"]])[1] == "") {
names(fargs[["legend"]])[1] = "x"
}
fargs[["legend_args"]] = modifyList(fargs[["legend"]], fargs[["legend_args"]])
fargs[["legend"]] = NULL
}
fargs$y = fargs$ymin = fargs$ymax = fargs$ylab = fargs$xlab = NULL
Expand Down
Loading