Closed clauswilke closed 6 years ago
I've made a branch draw_grob
to investigate what's going on. Fixing this will likely require re-implementation of the draw_grob
function, if it is possible to fix at all.
One thing I've learned already is that clipping doesn't work very well in grid, because nested clip areas aren't possible. And, gtable_col()
by default switches off any clipping that may have been set. See this issue I've filed for gtable.
Merged the branch back into master. draw_grob
is now reimplemented, which was useful for several reasons. However, the issue of drawing artifacts may not be solvable.
I have solved the problem. The issue can be avoided through appropriate settings in par()
before plotting.
p1 <- ggplot(mpg, aes(displ, cty, color=factor(cyl))) + geom_point()
dev.new()
par(xpd = NA, # switch off clipping, necessary to always see axis labels
bg = "transparent", # switch off background to avoid obscuring adjacent plots
oma = c(2, 2, 0, 0)) # move plot to the right and up
plot(sqrt)
p6 <- recordPlot()
dev.off()
p7 <- function() image(volcano)
p8 <- gtable::gtable_col("circle", list(grid::circleGrob()))
plot_grid(p1, p6, p7, p8, scale = c(1, .9, .9, .9))
this is amazing, thank you! looks so good.
is it possible to do the clipping and background automatically? i assume they’ll be always useful in the context of cowplot.
the problem seems to always appears with recordedplot instances. so maybe we could set the pars when replaying those?
I did something similar a years ago, when I try to let base plot users can also generate a hexsticker in R using my hexSticker package.
I just got an idea of making it to be supported by cowplot
and created the base2grob without aware of this (thanks @clauswilke for the link).
Closing this issue. There have been huge improvements on this front, and this now generally works without problems.
p1 <- ggplot(mpg, aes(displ, cty, color=factor(cyl))) + geom_point()
p2 <- ~plot(sqrt)
p3 <- function() image(volcano)
p4 <- gtable::gtable_col("circle", list(grid::circleGrob()))
plot_grid(p1, p2, p3, p4)
Also, if the drawing area becomes too small, cowplot notices and displays an error.
awesome!
See discussion here.
Tagging @flying-sheep who is part of this discussion.