grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
226 stars 7 forks source link

Support cex and bg #50

Closed grantmcdermott closed 1 year ago

grantmcdermott commented 1 year ago

Closes #48. Closes #49.

In addition to specifying these parameters manually, this PR also permits bg = "by" (similar to existing "by" keyword support for lty and pch).

I haven't added cex = "by" keword support yet, because I need to solve the potential problem of dual legend placement, e.g. one legend for colors and another for cex/size. However, once that's been cracked then it should be fairly trivial to support "bubble" plot types (c.f., #29).

Quick example of what this PR allows:

library(plot2)

palette("Tableau 10")
palette(adjustcolor(palette() , 0.3))

plot2(
    Sepal.Length ~ Petal.Length | Species, iris,
    pch = 21,
    col = "black",
    bg = "by",
    cex = 2
)

Created on 2023-07-28 with reprex v2.0.2

vincentarelbundock commented 1 year ago

Looks fantastic! Well done!

Two examples:

library(plot2)

palette("Tableau 10")
palette(adjustcolor(palette() , 0.3))

# Should `col` accept "by"?
plot2(
    Sepal.Length ~ Petal.Length | Species, iris,
    pch = 21,
    col = "by",
)
# Error in plot.xy(xy.coords(x, y), type = type, ...): invalid color name 'by'

# Default looks really pale on my screen
plot2(Petal.Length ~ Sepal.Length | Species, iris)
vincentarelbundock commented 1 year ago

Looks really great overall. I left some comments. Once you've made decisions on those, I won't have anything else to add and think it's good to merge.

grantmcdermott commented 1 year ago

Super, thanks @vincentarelbundock.

Minor aside RE the paleness of this palette. That should be resolved by selecting a solid point type (e.g., pch = 19). Or, by keeping the filled point type (pch = 21) but explicitly selecting some fill (e.g. bg = "by" / bg = "grey", etc.)