Skip to content

Plot margins #211

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
cpsievert opened this issue Apr 30, 2015 · 6 comments
Closed

Plot margins #211

cpsievert opened this issue Apr 30, 2015 · 6 comments

Comments

@cpsievert
Copy link
Collaborator

As it appears on page 60 of Hadley's PhD thesis, there are perceptual issues with plotting data next to the margin in the plot. It goes on to say:

For continuous data, 5% extra space is added, and for discrete data half a bar is added. These can be fine tuned by the user if necessary.

In plotly, we have the luxury of zooming/panning, but it'd be nice if we could match this default behaviour in ggplot2.

@cpsievert
Copy link
Collaborator Author

Whoops, I think this is related to the checkmark titled "add some more spacing around the graph: expand the range" here.

@cpsievert cpsievert modified the milestone: v1.0 May 30, 2015
@cpsievert
Copy link
Collaborator Author

For a plot with a single panel, layout(margin = ...) would be a solution, but what about multiple panels?

@cpsievert
Copy link
Collaborator Author

And, more generally, we should be respecting the expand argument:

qplot(1:10, 1:10)
# versus
qplot(1:10, 1:10) + 
  scale_x_continuous(expand = c(0,0)) + 
  scale_y_continuous(expand = c(0,0))

@westonplatter
Copy link

@cpsievert happy to help out on this since I ran into this issue - any pointers you might be able to provide before I jump in?

@cpsievert
Copy link
Collaborator Author

The "proper" way to do this is probably going to change when the new version of ggplot2 hits. So, if you want to tackle this, I recommend working from our fix for the dev version of ggplot2. This will likely be merged within a month from now when the new ggplot2 hits CRAN.

Right around here we start to translate axis information. Somewhere in there we need to set the proper range for each axis. Problem is, I'm not exactly sure the best way to find the range from the plot object. Once we have the proper ranges, it won't be hard to translate to plotly:

p <- qplot(data = mtcars, mpg, geom = "density")
g <- plotly_build(p)
g$layout$xaxis <- modifyList(g$layout$xaxis, list(range = c(5, 50)))
g

@cpsievert
Copy link
Collaborator Author

This should be fixed in f1900cc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants