grantmcdermott / tinyplot

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

Facet support #79

Closed grantmcdermott closed 7 months ago

grantmcdermott commented 8 months ago

I'm working towards basic facet support in https://github.com/grantmcdermott/plot2/tree/facets.

Quick example of what's possible so far.

devtools::load_all("~/Documents/Projects/plot2")
#> ℹ Loading plot2

data("penguins", package = "palmerpenguins")

par(pch = 19)

# basic
with(
  penguins,
  plot2(
    x = flipper_length_mm, y = body_mass_g,
    facet = species
  )
)


# fancier version with addtional args (incl. interaction with "by" arg)
with(
  penguins,
  plot2(
    x = flipper_length_mm, y = body_mass_g,
    facet = species, by = sex,
    main = "penguins",
    grid = TRUE, frame = FALSE
  )
)

Created on 2023-10-27 with reprex v2.0.2

Some outstanding issues that I'd like to resolve:

  1. At the moment, the facet arg is specified as a standard, single atomic var. Do we instead want to enable facet support via a (potentially two-sided) formula? This might be the most natural way to enable ggplot2-style facet grid, a la facet = rows ~ cols... Or, do you want to support both methods somehow?
  2. At the moment, facets are arranged by window columns (i.e., in a single row). Should we try to do something smarter here, like automatically fold into "square" rows and columns?
  3. At the moment, the axes are printed for all facets. Do we want to only print these for the exterior facets to avoid duplication?
  4. Do we want to enable additional customization of facet options, probably via a list argument? This could include some of the things that I've mentioned above, e.g. controlling the number of cols/rows, printing of axes, etc. But I'm worried that it creates an additional maintenance burden.