Skip to content

Customizable facet strip text. #98

Closed

Description

@grantmcdermott

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

Activity

  1. grantmcdermott commented on Jan 23, 2024

    @grantmcdermott
    OwnerAuthor

    Complementarity: There's no way to rotate the RHS facet mtext for facet_grid cases, so that it faces outwards. (Reason: it doesn't support a srt argument and las doesn't give us that either.) So we'd have to go through a bespoke text approach anyway (as above: using srt = 270 to rotate outwards).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions