grantmcdermott / tinyplot

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

Allow "by" convenience keyword for pch and bty args #28

Closed grantmcdermott closed 1 year ago

grantmcdermott commented 1 year ago

Fixes #27.

Tl;DR Users can opt into varying by groups along pch and lty via the "by" convenience keyword. The possibility for manual adjustment (#5) should still work the same, but this makes the process a bit less error prone from the user side.

Quick examples:

library(plot2)

plot2(
  Temp ~ Day | Month,
  data = airquality,
  type = "l",
  col = "black", # override automatic group colours
  lty = "by"     # change line type by group instead
)


# Should automatically respond (and recycle if necessary) to global par settings

par(pch=16)
plot2(
  Temp ~ Day | Month,
  data = airquality,
  type = "b",
  palette = "Tableau 10",
  pch = "by", # pch adjustment should be from 16 onwards
  lty = "by"
)

Created on 2023-04-15 with reprex v2.0.2

vincentarelbundock commented 1 year ago

Oh, I get it now! Users can still feed a vector manually to lty, but using the "by" shortcut string calculates the number of groups automatically.

This is very very nice! Well done.

zeileis commented 1 year ago

🚀

grantmcdermott commented 1 year ago

Great. Happy for me to merge?