fix(logo): reserve a logo band, keep patchwork panels, and preserve logo aspect (#20)

The logo gets its own band (logo_height inches) instead of negative
margins, so captions are no longer clipped. Patchwork compositions go
through patchworkGrob() so every panel survives. font_scale defaults to 1.
make_logo_grob() sizes by height so the logo keeps its shape on any canvas.

Closes #20

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Sonnet 5.5 committed 2026-10-15 15:27:55 -04:00
1 parent d6e3ba2fb4
commit 0561df4221
6 files changed
+171 -72

No files matched your search

+17 -9
View File
@@ -8,29 +8,37 @@ add_logo(
plot,
logo,
margin_param = NULL,
font_scale = 1.1,
position = c("bottom-right", "bottom-left", "top-right", "top-left")
font_scale = 1,
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
logo_height = 0.5
)
}
\arguments{
\item{plot}{a ggplot2 grob}
\item{plot}{a ggplot2 object, or a patchwork composition}
\item{logo}{a logo grob created by make_logo_grob()}
\item{margin_param}{a numeric specifying what margin to add or subtract to align the logo}
\item{margin_param}{Optional numeric. Replaces the plot margin (in points)
on the side next to the logo. `NULL` (default) leaves the plot's margins
alone.}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to text
sizes before composing the plot with the logo. Default `1.1` inflates
text by ~10 \% to compensate for the viewport shrinkage caused by
[gridExtra::arrangeGrob()]. Set to `1` to disable.}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to the
base text size before composing. Default `1` leaves typography unchanged.}
\item{position}{Character. Corner placement for the logo: `"bottom-right"`
(default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
whether the logo is placed above or below the plot.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo. Default `0.5`.}
}
\value{
a grob with a logo attached to it ready to plot
}
\description{
Add a logo to a ggplot2 object
The logo gets its own band of reserved height (`logo_height`, in inches)
below or above the plot, so it cannot overlap the plot's caption or push
anything off the canvas. Patchwork compositions are converted with
[patchwork::patchworkGrob()] so every panel and the
[patchwork::plot_annotation()] survive.
}
+2 -2
View File
@@ -10,7 +10,7 @@ add_logo_ga(
nrow = 1,
widths = NULL,
margin_param = NULL,
font_scale = 1.1
font_scale = 1
)
}
\arguments{
@@ -25,7 +25,7 @@ add_logo_ga(
\item{margin_param}{a number giving the adjustment up or down to help manually align logo and captions}
\item{font_scale}{Numeric. Multiplicative scaling factor applied to text
sizes before composing. Default `1.1`. See [add_logo()] for details.}
sizes before composing. Default `1`. See [add_logo()] for details.}
}
\value{
a grid object
+7 -4
View File
@@ -10,7 +10,8 @@ civilytics_logo(
variant = c("light", "dark"),
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
margin_param = NULL,
font_scale = 1.1
font_scale = 1,
logo_height = 0.5
)
}
\arguments{
@@ -28,9 +29,11 @@ civilytics_logo(
\item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to
[add_logo()].}
\item{font_scale}{Numeric. Inflate text sizes by this factor to compensate
for viewport shrinkage when composing with [gridExtra::arrangeGrob()].
Default `1.1` (~10 \% inflation). Set to `1` to disable.}
\item{font_scale}{Numeric. Multiplies the plot's base text size before
composing. Default `1` leaves typography unchanged.}
\item{logo_height}{Numeric. Height in inches of the band reserved for the
logo. Default `0.5`.}
}
\value{
A grob (from [gridExtra::arrangeGrob()]) ready to draw with