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

Adding theme(panel.border=element_rect(...)) resets the plot #659

Closed
jrnold opened this issue Sep 8, 2012 · 5 comments
Closed

Adding theme(panel.border=element_rect(...)) resets the plot #659

jrnold opened this issue Sep 8, 2012 · 5 comments

Comments

@jrnold
Copy link
Contributor

jrnold commented Sep 8, 2012

The following code produces a weird error. It renders the plot twice, the second time producing a plot with almost nothing on it. This doesn't appear when adding themes with other elements.

dsamp <- diamonds[sample(nrow(diamonds), 1000), ] 
(qplot(carat, price, data=dsamp, colour=clarity)
 + theme(panel.border = element_rect()))

This produces the same error

(qplot(carat, price, data=dsamp, colour=clarity)
 + theme(panel.border = element_rect(colour="black")))

This doesn't produce an error

(qplot(carat, price, data=dsamp, colour=clarity)
 + theme(panel.background = element_rect(colour="black")))
@wch
Copy link
Member

wch commented Sep 8, 2012

Previously the default fill for theme_rect() was NA, but now it default to the value set by the top-level rect element. In theme_grey(), this top-level fill value is white. The white fill is overlaid on the plot, which is why you can't see anything. To make it go away, set fill=NA:

dsamp <- diamonds[sample(nrow(diamonds), 1000), ]

qplot(carat, price, data=dsamp, colour=clarity) +
  theme(panel.border=element_rect(fill=NA))

@jrnold
Copy link
Contributor Author

jrnold commented Sep 8, 2012

Thanks. I guess I was confused about the difference between panel.border and panel.background.

@jrnold jrnold closed this as completed Sep 8, 2012
@wch
Copy link
Member

wch commented Sep 8, 2012

No worries. It's true that the difference isn't well documented. The purpose for panel border is to draw a bounding rectangle that is on top of things like tick marks. I've improved the help for it in the dev version:
https://github.com/hadley/ggplot2/blob/master/R/theme.r#L127

@jrnold
Copy link
Contributor Author

jrnold commented Sep 8, 2012

I'm glad I made the mistake; this makes a lot more sense now.

@thesickish
Copy link

Thanks for the help, wch! I had the exact same problem. It would be good to add this note to http://docs.ggplot2.org/0.9.2.1/theme.html as, currently, panel.border makes the entire graph disappear (in the example, ~3/4 of the way down the page)..

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 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

3 participants