2

I have points on the edge of a plot which is clipped off by facets.

Here is a dummy example based on this question, since it is related.

library(ggplot2)
df1 <- data.frame(x=1:10,y=1:10,c=rep(c("a","b"),each=5))

p <- ggplot(df1,aes(x,y)) + 
  geom_point(size=10)+
  scale_y_continuous(expand=c(0,0))+
  facet_grid(c~.)

print(p)

clipped-facet

I have tried as below. But this does not affect facet clipping.

gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] <- "off"
grid.draw(gt)

Also tried

gt$layout$clip[gt$layout$name=="strip-right"] <- "off"

facet-clip-2

Changing axis limits is not the solution I am looking for. This is a dummy example and probably not the best example. But, I have a more complex situation where points are clipped off by facet and the axis limits are fixed too.

Is it possible to have the point shown over the facet or the facet moved a bit to the right.

Community
  • 1
  • 1
mindlessgreen
  • 11,059
  • 16
  • 68
  • 113
  • Why are you setting `expand` to 0? If anything, you need it to be larger than the default: `ggplot(df1, aes(x, y)) + geom_point(size = 10) + scale_y_continuous(expand = c(.15, .15)) + facet_grid(c ~ .)` – alistaire Dec 01 '16 at 15:27
  • 1
    you had the right idea, turning off clipping helped, but now the bottom facet is simply being drawn over the top one. You could either have a transparent panel background, increase the inter-panel spacing, or change the z order in the gtable. That being said, these are suggestions for the technical problem, in practice I would also recommend expanding the axes, it just looks much better and won't have unfortunate side-effects. – baptiste Dec 01 '16 at 18:41
  • @baptiste That worked. I didn't think of that. This is what I needed `theme(strip.background=element_rect(fill=NA))` to fix the facet label issue. Thanks. – mindlessgreen Dec 01 '16 at 21:56

0 Answers0