Open rjake opened 2 years ago
Maybe:
n <- 123
ideal_ratio <- 1.6
base_rows <- ceiling(sqrt(n / ideal_ratio))
base_cols <- ceiling(n / base_rows)
alt_cols <- base_cols - 1
alt_rows <- ceiling(n / alt_cols)
wider <- list(
rows = base_rows,
cols = base_cols,
res = base_rows * base_cols,
delta = abs(ideal_ratio - (base_cols / base_rows))
)
thinner <- list(
cols = alt_cols,
rows = alt_rows,
res = alt_rows * alt_cols,
delta = abs(ideal_ratio - (alt_cols / alt_rows))
)
if (wider$delta < thinner$delta) {
c(x = wider$cols, y = wider$rows)
} else {
c(x = thinner$cols, y = thinner$rows)
}
Also review this cheatsheet https://raw.githubusercontent.com/rstudio/cheatsheets/main/how-big-is-your-graph.pdf
See scratchwork
facet_wrap()
doesn't always pick the right # forncol =
. I'd like to dynamically get the right # columns / rows to either have an ideal aspect ratio (each plot is 1:1.6 or fewest missing squares)Original assessment by Bridget R.