Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ddd21fd
working prototype for continuous legend
grantmcdermott Feb 11, 2024
a98cb8b
Adjust old test
grantmcdermott Feb 11, 2024
61fc776
Document legend.ugc behaviour
grantmcdermott Feb 11, 2024
25d46fd
switch to rasterImage gradient swatch
grantmcdermott Feb 12, 2024
0706843
typo
grantmcdermott Feb 12, 2024
7cf6de7
close #124
grantmcdermott Feb 14, 2024
64fb1b9
Fix inner gradient legend placement
grantmcdermott Feb 14, 2024
a093b86
Update example
grantmcdermott Feb 14, 2024
8431eb7
Merge branch 'main' into continuous-legend
grantmcdermott Feb 14, 2024
914e474
Fix check failures after main merge
grantmcdermott Feb 14, 2024
75bed77
Catch if bg = "by" and col is atomic
grantmcdermott Feb 16, 2024
7f37a19
Add tests
grantmcdermott Feb 16, 2024
c157e1f
Clean up internal code and comments
grantmcdermott Feb 16, 2024
c72f5f1
Consistent snake_case
grantmcdermott Feb 16, 2024
8bc2317
NEWS and version bump
grantmcdermott Feb 16, 2024
c39cc00
Update README and vignette
grantmcdermott Feb 16, 2024
8a1fa0b
fix badge
grantmcdermott Feb 16, 2024
794ad95
Update NEWS.md
grantmcdermott Feb 16, 2024
0a56194
fix label alignment
grantmcdermott Feb 19, 2024
ac70f45
better lab positioning still
grantmcdermott Feb 19, 2024
e48cd4d
fix bg = scalar bug caught by Achim
grantmcdermott Feb 19, 2024
1680dfc
Another part of the previous bug fix
grantmcdermott Feb 19, 2024
c38981a
catch for ordered factors
grantmcdermott Feb 20, 2024
9be47a9
update tests
grantmcdermott Feb 20, 2024
3ec53eb
add bg scalar test
grantmcdermott Feb 20, 2024
02c4453
Remove legend.ugc logic
grantmcdermott Feb 20, 2024
2a8c256
Use adjusted viridis palette as default for gradient legend
grantmcdermott Feb 22, 2024
35a47ef
Update tests following new gradient palette default
grantmcdermott Feb 22, 2024
c7956e8
Minor test tweak
grantmcdermott Feb 22, 2024
223dd28
Re-run README examples
grantmcdermott Feb 22, 2024
dcdda8a
Update docs
grantmcdermott Feb 22, 2024
a7085be
tweak
grantmcdermott Feb 22, 2024
1ae3e2f
Update vignette
grantmcdermott Feb 22, 2024
4b46844
Fix namespace note
grantmcdermott Feb 22, 2024
ca683d8
Fix R CMD note
grantmcdermott Feb 22, 2024
243a8ee
Thanks Achim in NEWS
grantmcdermott Feb 22, 2024
29096a6
Close #130
grantmcdermott Feb 22, 2024
6a68cde
wording tweak
grantmcdermott Feb 22, 2024
4836c20
Interpolate gradient colors if necessary
grantmcdermott Feb 22, 2024
3ff92fe
Ensure correct reverse order for gradient if user supplies n = 100 cols
grantmcdermott Feb 27, 2024
23acb74
Use restricted (and reversed) viridis default palette for ordered fac…
grantmcdermott Feb 27, 2024
78b1bbe
minor doc update
grantmcdermott Feb 27, 2024
6de6c12
color interpolation should respect alpha channel
grantmcdermott Mar 2, 2024
79f2888
Basic lwd support
grantmcdermott Mar 7, 2024
39b592e
Merge branch 'main' into lwd
grantmcdermott Mar 7, 2024
6ca4c94
update readme figure from main too
grantmcdermott Mar 7, 2024
d5797d8
better catch for 'p'
grantmcdermott Mar 8, 2024
0554c51
Merge in main
grantmcdermott Mar 8, 2024
69affcc
Fix
grantmcdermott Mar 8, 2024
f21380d
lwd catches for other types
grantmcdermott Mar 8, 2024
3c5443b
incidental update for tests
grantmcdermott Mar 8, 2024
61aea45
Tweak by_lwd logic
grantmcdermott Mar 9, 2024
f128a5a
Update / add lwd to by_aesthestics tests
grantmcdermott Mar 9, 2024
b4891cd
NEWS and version bump
grantmcdermott Mar 9, 2024
b5b05ee
Catch for direct draw_legend calls
grantmcdermott Mar 9, 2024
aff1207
Docs
grantmcdermott Mar 9, 2024
f8c2f70
typos
grantmcdermott Mar 9, 2024
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.9001
Version: 0.0.5.9002
Authors@R:
c(
person(
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# News

## 0.0.5.9001 (development version)
## 0.0.5.9002 (development version)

New features:

Expand All @@ -13,6 +13,10 @@ final implementation. (#122 @grantmcdermott)
- Ordered factors now inherit a discrete sequential color palette ("viridis") by
default. Thanks to @zeileis for the suggestion. (#130 @grantmcdermott)
- Support user-supplied polygons. (#127 @grantmcdermott)
- Support for the `lwd` argument for adjusting line widths. Similar to `pch`,
`lty`, etc. this arguments also accepts a "by" convenience keyword to
automatically vary line widths by group. (#134 @grantmcdermott)


## 0.0.5

Expand Down
33 changes: 31 additions & 2 deletions R/by_aesthetics.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ by_pch = function(ngrps, type, pch=NULL) {

by_lty = function(ngrps, type, lty=NULL) {

# don't care about line type, return NULL
# We only care about line types, otherwise return NULL
if (!type %in% c("l", "b", "o", "c", "h", "s", "S", "ribbon")) {
out = NULL

Expand Down Expand Up @@ -212,4 +212,33 @@ by_lty = function(ngrps, type, lty=NULL) {
}

return(out)
}
}


by_lwd = function(ngrps, type, lwd=NULL) {

lwd_base = par("lwd")
lwd_floor = lwd_base / min(5, max((ngrps-1), 1))
lwd_ceiling = lwd_base * min(5, ngrps)

no_lwd = FALSE
# special "by" convenience keyword
if (!is.null(lwd) && length(lwd)==1 && lwd=="by") {
no_lwd = TRUE # skip checks below
lwd = seq(lwd_floor, lwd_ceiling, length.out = ngrps)
} else if (is.null(lwd)) {
no_lwd = TRUE
lwd = NULL
}

if (!no_lwd) {
if (!is.atomic(lwd) || !is.vector(lwd) || !is.numeric(lwd) || (length(lwd) != 1 && length(lwd) != ngrps)) {
stop(sprintf("`lwd` must be `NULL` or a numeric vector of length 1 or %s.", ngrps), call. = FALSE)
}
if (length(lwd) == 1) {
lwd = rep(lwd, ngrps)
}
}

return(lwd)
}
5 changes: 5 additions & 0 deletions R/draw_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @param type Plotting type(s), passed down from `tinyplot`.
#' @param pch Plotting character(s), passed down from `tinyplot`.
#' @param lty Plotting linetype(s), passed down from `tinyplot`.
#' @param lwd Plotting line width(s), passed down from `tinyplot`.
#' @param col Plotting colour(s), passed down from `tinyplot`.
#' @param bg Plotting character background fill colour(s), passed down from `tinyplot`.
#' @param cex Plotting character expansion(s), passed down from `tinyplot`.
Expand Down Expand Up @@ -96,6 +97,7 @@ draw_legend = function(
type = NULL,
pch = NULL,
lty = NULL,
lwd = NULL,
col = NULL,
bg = NULL,
cex = NULL,
Expand Down Expand Up @@ -142,6 +144,9 @@ draw_legend = function(
if (!exists("title", where = legend_args)) legend_args[["title"]] = by_dep
if (is.null(legend_args[["pch"]])) legend_args[["pch"]] = pch
if (is.null(legend_args[["lty"]])) legend_args[["lty"]] = lty
if (!is.null(type) && !(type %in% c("p", "ribbon", "polygon"))) {
if (is.null(legend_args[["lwd"]])) legend_args[["lwd"]] = lwd
}
if (is.null(legend_args[["col"]])) legend_args[["col"]] = col
if (is.null(legend_args[["bty"]])) legend_args[["bty"]] = "n"
if (is.null(legend_args[["horiz"]])) legend_args[["horiz"]] = FALSE
Expand Down
30 changes: 25 additions & 5 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
#' be necessary unless users wish to override the automatic colors produced by
#' this grouping process. Typically, this would only be done if grouping
#' features are deferred to some other graphical parameter (i.e., passing the
#' "by" keyword to one of `pch`, `lty`, or `bg`; see below.)
#' "by" keyword to one of `pch`, `lty`, `lwd`, or `bg`; see below.)
#' @param pch plotting "character", i.e., symbol to use. Character, integer, or
#' vector of length equal to the number of categories in the `by` variable.
#' See `pch`. In addition, users can supply a special `pch = "by"` convenience
Expand All @@ -161,6 +161,12 @@
#' line type will automatically loop over the number groups. This automatic
#' looping will begin at the global line type value (i.e., `par("lty")`) and
#' recycle as necessary.
#' @param lwd line width. Numeric scalar or vector of length equal to the
#' number of categories in the `by` variable. See `lwd`. In addition, users
#' can supply a special `lwd = "by"` convenience argument, in which case the
#' line width will automatically loop over the number of groups. This
#' automatic looping will be centered at the global line width value (i.e.,
#` par("lwd")`) and pad on either side of that.
#' @param bg background fill color for the open plot symbols 21:25 (see
#' `points.default`), as well as ribbon and area plot types. For the latter
#' group---including filled density plots---an automatic alpha transparency
Expand Down Expand Up @@ -394,6 +400,7 @@ tinyplot.default = function(
legend = NULL,
pch = NULL,
lty = NULL,
lwd = NULL,
col = NULL,
bg = NULL,
fill = NULL,
Expand Down Expand Up @@ -563,6 +570,8 @@ tinyplot.default = function(
pch = by_pch(ngrps = ngrps, type = type, pch = pch)

lty = by_lty(ngrps = ngrps, type = type, lty = lty)

lwd = by_lwd(ngrps = ngrps, type = type, lwd = lwd)

# palette = substitute(palette)
col = by_col(
Expand Down Expand Up @@ -724,6 +733,7 @@ tinyplot.default = function(
type = type,
pch = pch,
lty = lty,
lwd = lwd,
col = col,
bg = bg,
gradient = by_continuous,
Expand Down Expand Up @@ -1120,6 +1130,7 @@ tinyplot.default = function(
ibg = bg[i]
ipch = pch[i]
ilty = lty[i]
ilwd = lwd[i]

## Inner loop over the "facet" variables
for (ii in seq_along(idata)) {
Expand Down Expand Up @@ -1163,7 +1174,8 @@ tinyplot.default = function(
x1 = xx,
y1 = yymax,
col = icol,
lty = ilty
# lty = ilty,
lwd = ilwd
)
}
if (type == "errorbar") {
Expand All @@ -1173,7 +1185,8 @@ tinyplot.default = function(
x1 = xx,
y1 = yymax,
col = icol,
lty = ilty,
# lty = ilty,
lwd = ilwd,
length = 0.05,
angle = 90,
code = 3
Expand All @@ -1190,7 +1203,8 @@ tinyplot.default = function(
## rather hardcode "p" to avoid warning message about "pointrange"
type = "p",
pch = ipch,
lty = ilty,
# lty = ilty,
lwd = ilwd,
cex = cex
)
} else if (type %in% c("l", "o", "b", "c", "h", "s", "S", "ribbon")) {
Expand All @@ -1202,7 +1216,8 @@ tinyplot.default = function(
col = icol,
type = type,
pch = ipch,
lty = ilty
lty = ilty,
lwd = ilwd
)
if (rtype) type = "ribbon"
} else if (type == "polygon") {
Expand All @@ -1212,6 +1227,7 @@ tinyplot.default = function(
border = icol,
col = ibg,
lty = ilty,
lwd = ilwd
)
} else {
stop("`type` argument not supported.", call. = FALSE)
Expand Down Expand Up @@ -1255,6 +1271,7 @@ tinyplot.formula = function(
pch = NULL,
col = NULL,
lty = NULL,
lwd = NULL,
par_restore = FALSE,
formula = NULL,
subset = NULL,
Expand Down Expand Up @@ -1432,6 +1449,7 @@ tinyplot.formula = function(
pch = pch,
col = col,
lty = lty,
lwd = lwd,
par_restore = par_restore,
...
)
Expand Down Expand Up @@ -1463,6 +1481,7 @@ tinyplot.density = function(
pch = NULL,
col = NULL,
lty = NULL,
lwd = NULL,
bg = NULL,
fill = NULL,
par_restore = FALSE,
Expand Down Expand Up @@ -1636,6 +1655,7 @@ tinyplot.density = function(
bg = bg,
fill = fill,
lty = lty,
lwd = lwd,
par_restore = par_restore,
...
)
Expand Down
Loading