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

clipping with facets #1929

Closed
tobiasgerstenberg opened this issue Nov 28, 2016 · 1 comment
Closed

clipping with facets #1929

tobiasgerstenberg opened this issue Nov 28, 2016 · 1 comment

Comments

@tobiasgerstenberg
Copy link

It used to be possible to put text outside of the plots by turning off the clipping. This doesn't seem to be possible anymore in plots that use facets (but still works if no facets are used). It would be great if this could be fixed such that it's possible to put text outside of plots even when using facets.

Here is a minimal working example:

library(ggplot2)
library(grid)

df.plot = data.frame(x = 1, y = 1, facet = 'facet', stringsAsFactors = F)
df.text = data.frame(x = 1, y = -0.3, label = 'test', facet = 'facet', stringsAsFactors = F)

p = ggplot(df.plot,aes(x = x, y = y))+
  facet_grid(~facet)+ # 'test' is only printed outside of the plot if faceting is turned off
  geom_point()+
  geom_text(data = df.text,aes(x=x,y=y,label=label))+
  coord_cartesian(xlim = c(0, 2),ylim=c(0,2),expand=F)+
  theme(plot.margin=unit(c(2,2,2,2),"cm"))
gt = ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] = "off"
grid.draw(gt)
@tobiasgerstenberg
Copy link
Author

replacing gt$layout$clip[gt$layout$name=="panel"] = "off" with gt$layout$clip = "off" solves the problem

@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