Skip to content

Text size switch #5260

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

Merged
merged 7 commits into from
Apr 24, 2023
Merged

Text size switch #5260

merged 7 commits into from
Apr 24, 2023

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #3799.

Briefly, it adds a size_unit parameter to geom_text/label() that allows one to use "pt" to have the size interpreted as points.

Example:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot() +
  annotate("text",  x = -1, y = 0, label = "Abc", size = 10, size_unit = "mm") +
  annotate("text",  x = 1,  y = 0, label = "Def", size = 10, size_unit = "pt") +
  annotate("label", x = -1, y = 1, label = "Ghi", size = 10, size_unit = "mm") +
  annotate("label", x = 1,  y = 1, label = "Jkl", size = 10, size_unit = "pt") +
  xlim(-2, 2) + ylim(-1, 2)

Created on 2023-04-05 with reprex v2.0.2

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As garish as it is, arguments in ggplot2 are "." separated instead of "_" separated

@teunbrand
Copy link
Collaborator Author

Oops yes, fixed it

@thomasp85
Copy link
Member

I'm trying to figure out if mm and pt are too limiting since grid supports a multitude of units... maybe it is not so big a deal

@teunbrand
Copy link
Collaborator Author

I can see some utility for absolute units, but I'd have no idea what to expect for 1null or 1npc text sizes.

@thomasp85
Copy link
Member

yeah, I'm only thinking of adding the other absolute sizes, not the relative ones

@teunbrand
Copy link
Collaborator Author

I've added centimetres, inches and picas in addition to the points and millimetres. Other absolute units are 'bigpts', 'dida', 'cicero' and 'scaledpts', but I've never seen anybody use these in the wild, so I didn't add them. Let me know if you'd like to add these.

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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 this pull request may close these issues.

Add fontsize aesthetic to geom_text
2 participants