Skip to content

Alignment of multi-line text in plot axes #104

Closed

Description

@ak-nge

I'm currently in the process of switching all the theming specifications and defaults of my codebase over to {marquee} for its great and comprehensive functionality. During that, I stumbled upon the unexpected (by me, at least) behaviour described below. I noticed it while working with multi-line text on plot axes, but it could be a more general issue. I really hope to not have missed an obvious solution, but after working through the docs and issues for a good deal of time now, I could not find a working solution.

I'm on R v4.5.1 with {marquee} v1.2.1.

The issue I have occurs with multi-line text in axes of a plot . For example, on a horizontal axis, default behaviour of {ggplot2} is to center multi-line text.

library(tidyverse)
library(marquee)
p <- iris |>
  mutate(Species = paste0(Species, "\n\nlorem ipsum dolor sit amet")) |>
  ggplot(aes(Species)) +
  geom_bar()

# both lines are centered (as the single line would be)
p
Image

However, when the same theme is marquefied, alignment switches to left-align.

# both lines are left-aligned
p +
  marquefy_theme(theme_gray())
Image

From the docs I understand that the preferred way to adjust this would be via the style argument in element_marquee(). However, changing the alignment style on the axis.text level has no effect; centering is only applied when I target the axis.text.x specifically.

# specifiyng the alignment makes no difference...
p +
  marquefy_theme(theme_gray()) +
  theme(
    axis.text = element_marquee(
      colour = "red", # to test that it does apply this change
      style = classic_style(
        align = "center"
      )
    )
  )
Image
# ...unless done on the specific axis
p +
  marquefy_theme(theme_gray()) +
  theme(
    axis.text.x = element_marquee(
      colour = "red", # to test that it does apply this change
      style = classic_style(
        align = "center"
      )
    )
  )
Image

Ultimately, my question is: shouldn't a specification for axis.text overwrite a blank value for axis.text.x, etc.? Some further tests of variants look to me as if maybe marquefy_theme() sets values on some granularity level that then cannot be overwritten by a more general specification that is later applied. Is this the intended behaviour?

# example of applying a targeted `element_marquee()`, not marquefying the theme
p +
  theme(
    axis.text = element_marquee(
      colour = "red", # to test that it does apply this change
      style = classic_style(
        align = "center"
      )
    )
  )
Image

This is what I would have expected the plot to look like even if marquefy_theme(theme_gray()) had been called before the subsequent theme() adjustment.

Again, I'm sorry if I'm missing something obvious here, I might be blind from all the digging into debugging. 😅

Activity

  1. added a commit that references this issue on Nov 11, 2026
    8afb83f
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