Skip to content

Legend mis-alignement for parsing greek letters using scale::parse_format #4814

Closed

Description

@Sibojang9

In the first figure, the right-hand side legend is correctly aligned with the regular ggplot code. However, the greek characters were mis-aligned when labels=parse_format() is used to parse "microgram" in the second figure, as indicated by the gap (white space) next to the legend "1 ug". The erratic alignment behavior sounds like a bug to me.

library(ggplot2)
library(scales)
data <- data.frame(x=c(1,2),y=c(1,2),c= c("10000~mu*g","1~mu*g"))
ggplot(data,aes(x=x,y=y,color=c)) + geom_point()

ggplot(data,aes(x=x,y=y,color=c)) + geom_point()+ scale_colour_discrete(labels=parse_format()) 

Created on 2022-04-25 by the reprex package (v2.0.1)

Activity

  1. thomasp85 commented on May 12, 2022

    @thomasp85
    Member

    While poorly documented, the default justification for expressions in labels has always been right-aligned. This can of course be overwritten in the guide. I can't comment on the reason for this decision as it predates my time with ggplot2 (meaning it is ancient 🙂). This also means that it is probably too late to change as others may likely rely on the default behaviour...

  2. Sibojang9 commented on May 17, 2022

    @Sibojang9
    Author

    This is a typical sunk cost fallacy. It will take more toll to fix in future.

  3. thomasp85 commented on May 17, 2022

    @thomasp85
    Member

    Well, it's not really a bug so there is nothing to fix later. It was a poorly documented behaviour that is now properly documented.

  4. Sibojang9 commented on May 17, 2022

    @Sibojang9
    Author

    Do you have the link to the docu?

  5. thomasp85 commented on May 17, 2022

    @thomasp85
    Member

    ggplot2/R/guide-legend.r

    Lines 34 to 36 in eb0010e

    #' @param label.hjust A numeric specifying horizontal justification of the
    #' label text. The default for standard text is 0 (left-aligned) and 1
    #' (right-aligned) for expressions.

  6. Sibojang9 commented on May 17, 2022

    @Sibojang9
    Author

    Thank you so much for sharing.

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