Skip to content
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

Consider paddedTextGrob #1228

Closed
hadley opened this issue Jul 30, 2015 · 1 comment
Closed

Consider paddedTextGrob #1228

hadley opened this issue Jul 30, 2015 · 1 comment

Comments

@hadley
Copy link
Member

hadley commented Jul 30, 2015

Works the same way as textGrob() but has a length-4 vector defining padding around the grob. Would be used to theme the padding around labels. Currently it defaults to a fixed value which tends to be too small when font sizes get larger

@hadley
Copy link
Member Author

hadley commented Aug 3, 2015

base <- ggplot(df, aes(x, y)) + 
  geom_point() + 
  ylab("a longer\nlabel")

axis_y_title <- function(hjust, vjust, angle = 0, t = 0, b = 0, r = 0, l = 0) {
  marg <- margin(t, r, b, l)
  theme(axis.title.y = 
    element_text(margin = marg, hjust = hjust, vjust = vjust, angle = angle)
  )
}


# Centered: bottom, middle, top [OK]
base + axis_y_title(hjust = 0.5, vjust = 0)
base + axis_y_title(hjust = 0.5, vjust = 0.5)
base + axis_y_title(hjust = 0.5, vjust = 1)

# Left aligned: bottom, middle, top [OK]
base + axis_y_title(hjust = 0, vjust = 0)
base + axis_y_title(hjust = 0, vjust = 0.5)
base + axis_y_title(hjust = 0, vjust = 1)

# Now add larger margin on right
# [NOT OK: margin on both sides]
base + axis_y_title(hjust = 0.5, vjust = 0, r = 100)
base + axis_y_title(hjust = 0.5, vjust = 0.5, r = 100)
base + axis_y_title(hjust = 0.5, vjust = 1, r = 100)

# Left aligned: bottom, middle, top
# [OK]
base + axis_y_title(hjust = 0, vjust = 0, r = 100)
base + axis_y_title(hjust = 0, vjust = 0.5, r = 100)
base + axis_y_title(hjust = 0, vjust = 1, r = 100)

@hadley hadley closed this as completed in 47fc3d6 Aug 4, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant