Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sibojang9 opened this issue Apr 26, 2022 · 6 comments · Fixed by #4837
Closed

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

Sibojang9 opened this issue Apr 26, 2022 · 6 comments · Fixed by #4837

Comments

@Sibojang9
Copy link

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)

@thomasp85
Copy link
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...

@Sibojang9
Copy link
Author

Sibojang9 commented May 17, 2022

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

@thomasp85
Copy link
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.

@Sibojang9
Copy link
Author

Do you have the link to the docu?

@thomasp85
Copy link
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.

@Sibojang9
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants