feat: add position argument to civilytics_logo() for corner placement
R-CMD-check / R CMD check (push) Successful in 3m37s
R-CMD-check / R CMD check (push) Successful in 3m37s
Supports "bottom-right" (default), "bottom-left", "top-right", and "top-left". The position controls both horizontal alignment of the logo grob and whether it is placed above or below the plot. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-1
@@ -4,7 +4,13 @@
|
||||
\alias{add_logo}
|
||||
\title{Add a logo to a ggplot2 object}
|
||||
\usage{
|
||||
add_logo(plot, logo, margin_param = NULL, font_scale = 1.1)
|
||||
add_logo(
|
||||
plot,
|
||||
logo,
|
||||
margin_param = NULL,
|
||||
font_scale = 1.1,
|
||||
position = c("bottom-right", "bottom-left", "top-right", "top-left")
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{plot}{a ggplot2 grob}
|
||||
@@ -17,6 +23,10 @@ add_logo(plot, logo, margin_param = NULL, font_scale = 1.1)
|
||||
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{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.}
|
||||
}
|
||||
\value{
|
||||
a grob with a logo attached to it ready to plot
|
||||
|
||||
+23
-11
@@ -8,6 +8,7 @@ civilytics_logo(
|
||||
plot,
|
||||
type = c("wordmark", "mark"),
|
||||
variant = c("light", "dark"),
|
||||
position = c("bottom-right", "bottom-left", "top-right", "top-left"),
|
||||
margin_param = NULL,
|
||||
font_scale = 1.1
|
||||
)
|
||||
@@ -21,6 +22,9 @@ civilytics_logo(
|
||||
\item{variant}{Character. `"light"` (default) or `"dark"`. Passed to
|
||||
[make_logo_grob()].}
|
||||
|
||||
\item{position}{Character. Corner placement for the logo: `"bottom-right"`
|
||||
(default), `"bottom-left"`, `"top-right"`, or `"top-left"`.}
|
||||
|
||||
\item{margin_param}{Numeric or `NULL`. Manual margin adjustment passed to
|
||||
[add_logo()].}
|
||||
|
||||
@@ -33,8 +37,8 @@ A grob (from [gridExtra::arrangeGrob()]) ready to draw with
|
||||
[grid::grid.draw()].
|
||||
}
|
||||
\description{
|
||||
A convenience wrapper that creates the logo grob and attaches it below the
|
||||
plot in one call. Designed for use with the base pipe `|>`.
|
||||
A convenience wrapper that creates the logo grob and attaches it to a
|
||||
corner of the plot in one call. Designed for use with the base pipe `|>`.
|
||||
}
|
||||
\details{
|
||||
**Important:** R's `|>` has *higher* precedence than `+`, so you must
|
||||
@@ -58,18 +62,26 @@ library(ggplot2); library(grid)
|
||||
civilytics_logo() |>
|
||||
grid.draw()
|
||||
|
||||
# Dark theme with mark
|
||||
(ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics_dark()) |>
|
||||
civilytics_logo(variant = "dark", type = "mark") |>
|
||||
grid.draw()
|
||||
|
||||
# Disable font inflation
|
||||
# Top-right placement
|
||||
(ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics()) |>
|
||||
civilytics_logo(font_scale = 1) |>
|
||||
civilytics_logo(position = "top-right") |>
|
||||
grid.draw()
|
||||
|
||||
# Bottom-left with mark
|
||||
(ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics()) |>
|
||||
civilytics_logo(type = "mark", position = "bottom-left") |>
|
||||
grid.draw()
|
||||
|
||||
# Dark theme with mark in top-left
|
||||
(ggplot(mpg, aes(displ, hwy)) +
|
||||
geom_point() +
|
||||
theme_civilytics_dark()) |>
|
||||
civilytics_logo(variant = "dark", type = "mark",
|
||||
position = "top-left") |>
|
||||
grid.draw()
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -4,7 +4,11 @@
|
||||
\alias{make_logo_grob}
|
||||
\title{Get a Civilytics Logo grob}
|
||||
\usage{
|
||||
make_logo_grob(type = c("wordmark", "mark"), variant = c("light", "dark"))
|
||||
make_logo_grob(
|
||||
type = c("wordmark", "mark"),
|
||||
variant = c("light", "dark"),
|
||||
position = c("bottom-right", "bottom-left", "top-right", "top-left")
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{type}{Character. `"wordmark"` (default) uses the full wordmark.
|
||||
@@ -13,6 +17,10 @@ make_logo_grob(type = c("wordmark", "mark"), variant = c("light", "dark"))
|
||||
\item{variant}{Character. `"light"` (default) uses the dark logo for light
|
||||
backgrounds. `"dark"` uses the reverse (light) logo for dark backgrounds
|
||||
(pairs with [theme_civilytics_dark()]).}
|
||||
|
||||
\item{position}{Character. Corner placement for the logo: `"bottom-right"`
|
||||
(default), `"bottom-left"`, `"top-right"`, or `"top-left"`. Controls
|
||||
horizontal alignment of the logo grob.}
|
||||
}
|
||||
\value{
|
||||
A ggplot object (class `"gg"`) containing the logo grob.
|
||||
@@ -25,5 +33,6 @@ pipe-friendly [civilytics_logo()].
|
||||
\examples{
|
||||
logo <- make_logo_grob() # wordmark, light
|
||||
logo <- make_logo_grob("mark", "dark") # mark, dark
|
||||
logo <- make_logo_grob(position = "bottom-left") # left-aligned
|
||||
class(logo) # "gg" "ggplot"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user