Things like background fill, font colour and face (italic, bold, etc.) that the user could control through facet.args or par2.
Would probably require that we role our own combination of rect and text, rather than simply going through mtext. But that shouldn't be too problematic. Proof of concept:
curve(dnorm(x), -3, 3, col = "dodgerblue")
corners = par("usr") # Get the four corners of plot area (x1, x2, y1, y2)
# top side
line_height = grconvertY(1.1, from="char", to="user") - grconvertY(0, from="char", to="user")
rect(
corners[1], corners[4], corners[2], corners[4] + line_height,
col = "gray95", border = NA, xpd = TRUE
)
# mtext("Topside", side = 3, line = 0.1)
text(
x = mean(corners[1:2]),
y = corners[4],
"Topside",
adj = c(0.5, -0.5),
xpd = TRUE,
)
# right side
line_height = grconvertX(1.1, from="char", to="user") - grconvertX(0, from="char", to="user")
rect(
corners[2], corners[3], corners[2]+line_height, corners[4],
col = "gray95", border = NA, xpd = TRUE
)
# mtext("rightside", side = 4, line = 0.1)
text(
x = corners[2],
y = mean(corners[3:4]),
"Rightside", srt = 270,
adj = c(0.5, -0.5),
xpd = TRUE
)

Created on 2024-01-22 with reprex v2.1.0
Things like background fill, font colour and face (italic, bold, etc.) that the user could control through
facet.argsorpar2.Would probably require that we role our own combination of
rectandtext, rather than simply going throughmtext. But that shouldn't be too problematic. Proof of concept:Created on 2024-01-22 with reprex v2.1.0