grantmcdermott / tinyplot

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

Facet args (and some extras) #91

Closed grantmcdermott closed 9 months ago

grantmcdermott commented 10 months ago

This PR introduces a "facet.args" argument that allows users more fine-grained control over facet features. At the moment, only ncol and nrow are supported, but we can obviously add more as the need arises. (E.g. One to allow free axis limits/scales across facets.)

(FWIW @zeileis I tried to go via your "mfrow" argument idea at first. But I quickly ran into trouble because it requires users to specify both the desired no. of rows and columns ahead of time. There's a probably a smart way around this, but I think allowing separate ncol and nrow arguments is a pretty good alternative approach.)

Other features and changes bundled into this PR, addressing some issues from #90.

Examples

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

palette("dark")

data("penguins", package = "palmerpenguins")
penguins = na.omit(penguins)

with(
  penguins,
  plot2(
    x = flipper_length_mm, y = body_mass_g,
    by = sex,
    facet = species,
    main = "Palmer Penguins",
    frame = FALSE, grid = TRUE
  )
)


# Defaults to square arrangement if no. of facets > 3
with(
  penguins,
  plot2(
    x = flipper_length_mm, y = body_mass_g,
    by = sex,
    facet = interaction(sex, species, sep = "\n"),
    main = "Palmer Penguins",
    frame = FALSE, grid = TRUE
  )
)


# Override default arrangement with facet.args
with(
  penguins,
  plot2(
    x = flipper_length_mm, y = body_mass_g,
    by = sex,
    facet = interaction(sex, species, sep = "\n"),
    facet.args = list(ncol = 2),
    main = "Palmer Penguins",
    frame = FALSE, grid = TRUE
  )
)

Created on 2023-12-09 with reprex v2.0.2

grantmcdermott commented 10 months ago

Hmmm, altdoc CI check failing unexpectedly.

@etiennebacher @vincentarelbundock did something change on the altdoc side?

vincentarelbundock commented 10 months ago

Perhaps, but for some reason I never seem to use vapply, so I'm 98.7% sure this is code by @etiennebacher

etiennebacher commented 9 months ago

Yup, that was me, should be fixed on altdoc's main branch so you can re-run the CI here

vincentarelbundock commented 9 months ago

Thanks etienne. I re-ran Github actions and it passes.

grantmcdermott commented 9 months ago

Thanks both!