Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous / gradient legend #122

Merged
merged 43 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
43 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
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.9000
Version: 0.0.5.9001
Authors@R:
c(
person(
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ export(plt)
export(tinyplot)
export(tpar)
importFrom(grDevices,adjustcolor)
importFrom(grDevices,as.raster)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,extendrange)
importFrom(grDevices,hcl.colors)
importFrom(grDevices,hcl.pals)
importFrom(grDevices,palette)
importFrom(grDevices,palette.colors)
importFrom(grDevices,palette.pals)
importFrom(grDevices,recordGraphics)
importFrom(grDevices,xy.coords)
importFrom(graphics,Axis)
importFrom(graphics,abline)
Expand All @@ -30,6 +33,7 @@ importFrom(graphics,plot.new)
importFrom(graphics,plot.window)
importFrom(graphics,points)
importFrom(graphics,polygon)
importFrom(graphics,rasterImage)
importFrom(graphics,rect)
importFrom(graphics,segments)
importFrom(graphics,text)
Expand All @@ -38,6 +42,7 @@ importFrom(methods,as)
importFrom(stats,as.formula)
importFrom(stats,model.frame)
importFrom(stats,na.omit)
importFrom(stats,terms)
importFrom(stats,update)
importFrom(utils,head)
importFrom(utils,modifyList)
Expand Down
11 changes: 9 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# News

## 0.0.5.9000 (development version)

## 0.0.5.9001 (development version)

- Gradient legends are now supported if by a continuous variable is passed to
`by`. The exact behaviour depends on how many unique groups are detected within
the "by" variable. Specifically, a gradient legend will only be printed if more
than 5 unique groups are detected. But this behaviour can fine-tuned by the user
via the `tpar("legend.ugc")` parameter. Thanks to StackOverflow user mnel, whose
answer [here](https://stackoverflow.com/a/13355440) provided the inspiration for
the final implementation. (#122 @grantmcdermott)
grantmcdermott marked this conversation as resolved.
Show resolved Hide resolved
- Support user-supplied polygons. (#127 @grantmcdermott)

## 0.0.5
Expand Down
11 changes: 10 additions & 1 deletion R/by_aesthetics.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
by_col = function(ngrps = 1L, col = NULL, palette = NULL) {
by_col = function(ngrps = 1L, col = NULL, palette = NULL, gradient = NULL) {

if (is.null(gradient)) gradient = FALSE
if (isTRUE(gradient)) {
ngrps = 100L
}

# palette = substitute(palette, env = parent.env(environment()))

Expand Down Expand Up @@ -45,6 +50,10 @@ by_col = function(ngrps = 1L, col = NULL, palette = NULL) {
if (!is.na(pal_match)) {
if (pal_match < 1L) stop("'palette' is ambiguous")
palette_fun = palette.colors
if (isTRUE(gradient)) {
palette_fun2 = function(n, palette) colorRampPalette(palette.colors(palette = palette))(n)
palette_fun = palette_fun2
}
} else {
pal_match = charmatch(fx(palette), fx(hcl.pals()))
if (!is.na(pal_match)) {
Expand Down
Loading
Loading