Skip to content

Feature Request: Warn when axis title or axis label goes outside of the plot area #3282

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
billdenney opened this issue Apr 30, 2019 · 5 comments
Labels
feature a feature request or enhancement guides 📏 wip work in progress

Comments

@billdenney
Copy link
Contributor

Related to #3281 (but not the same).

When text goes outside of the plot area, usually the plot is less readable. It would help to have a warning when text goes outside of the plot area. In the example below, the x-axis labels appear to start at "b" and end at "I" because the text is cut off. It would help find unreadable figures if this resulted in a warning-- especially with automated reporting (like in knitr documents).

If implemented, a theme option to suppress the warning would be useful, too. It could be something like theme(warn.outside=TRUE), and it may have variants for warn.outside.axis.text, warn.outside.axis.text.x, warn.outside.axis.text.y, warn.outside.axis.title, warn.outside.axis.title.x, warn.outside.axis.title.y, warn.outside.title, warn.outside.subtitle, warn.outside.caption, and warn.outside.legend.

library(ggplot2)

data_with_long_names <-
  data.frame(
    A=c(paste0(rep(LETTERS, 3), collapse=""), paste0(rep(letters, 3), collapse="")),
    B=1
  )

# Feature request: This gives a warning
ggplot(data_with_long_names, aes(x=A, y=B)) +
  geom_point()

Created on 2019-04-30 by the reprex package (v0.2.0).

@smouksassi
Copy link

ggrepel would redraw if you resize the figure so this is possible for text that is part of the plot.
For axis labels why it is not possible ?
I would imagine several ways to avoid overlap:
Rotation

Having alternate vertical height ( first tick label go on an imaginary line 1, second tick label imaginary line 2 which is below line1 in a way that we have no overlap ( this was possible in splus back in time) it is like inserting line breaks with control of lineheight

Abbreviate

@thomasp85
Copy link
Member

It is certainly possible - also for an extension package. As said in the other issue, some of this is already being considered for ggplot2 proper and others can step up and implement the rest as extension

@paleolimbot
Copy link
Member

This is one of the items I'm hoping to make easier as part of the work for #3322, and the ability to extend as per #3329.

@paleolimbot paleolimbot added wip work in progress guides 📏 feature a feature request or enhancement and removed wip work in progress labels May 21, 2019
@hadley
Copy link
Member

hadley commented Jun 18, 2019

Closing as duplicate of #3281. I don't think we need two separate issues for the aspects of the same underlying problem.

@hadley hadley closed this as completed Jun 18, 2019
@lock
Copy link

lock bot commented Dec 15, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Dec 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement guides 📏 wip work in progress
Projects
None yet
Development

No branches or pull requests

5 participants