UpSetR icon indicating copy to clipboard operation
UpSetR copied to clipboard

empty first page in pdf output

Open ChristofferFlensburg opened this issue 6 years ago • 8 comments

Hi and thanks for a great package! I always link this package on twitter whenever I see a venn diagram with too many sets, as do many others.

For the (minor) issue I want to output a pdf, but it keeps producing an empty first page and the actual plot on the second page. For example

pdf('upsetExample.pdf', width=10, height=7)
example(upset)
dev.off()

produces the attached file on my system. upsetExample.pdf

I'm not experienced with ggplot, so not sure if this is a ggplot thing or an upset thing, sorry. It's not hard to manually delete the empty page, but I'd like to to automate over many files and then it becomes a bit annoying.

Thanks, and all the best, /Christoffer

ChristofferFlensburg avatar Sep 11 '17 01:09 ChristofferFlensburg

I believe setting the onefile parameter of pdf() to FALSE will fix this

JakeConway avatar Sep 11 '17 15:09 JakeConway

Thanks Jake.

It does indeed solve the issue with the empty first page, but it doesn't allow you to output multipage pdf. In my case I only wanted a single page, so it works around my issue, thanks!

The example code still produces a pdf with only the last plot as opposed to the desired 3 pages.

pdf('upsetExample.pdf', width=10, height=7, onefile=F)
example(upset)
dev.off()

upsetExample.pdf

So umm, feel free to close this unless you want to fix the multipage thing. I got what I needed, thanks.

ChristofferFlensburg avatar Sep 12 '17 01:09 ChristofferFlensburg

The reason for this, I believe, is that the upset plot functions (in UpSet.plot.R) contain calls to gridExtra:::grid.newpage(). This leads to blank pages being inserted. These calls should be removed, since they also prevent the user from (eg) inserting an upset plot as part of a larger grid object.

In fact, I think that the upset function should merely return the grid objects, and a separate function should handle the plotting...

alanocallaghan avatar Dec 01 '17 17:12 alanocallaghan

The onefile = FALSE solution doesn't work when you're using CairoPDF from the Cairo package.

mcbg avatar Dec 07 '17 12:12 mcbg

So has a true solution to this been found? I want to be able to use onefile=TRUE and not have that pesky blank first page. This issue is bigger than just an upset one. It has to do with using pdf to save multipage plots.

reesese avatar May 18 '18 16:05 reesese

I haven't had this issue in base plotting. After a quick google, it seems like an issue with ggplot and pdf(): https://github.com/wilkelab/cowplot/issues/24

According to Claus Wilke in that thread, ggsave() replaces pdf() for this situation.

ChristofferFlensburg avatar May 19 '18 09:05 ChristofferFlensburg

All suggested options worked for on global .env, once I used within my own function the only thing that worked was (maybe because of .env):

png(plot_filepath)
  print({
    plot_upset<-upset(fromExpression(upset_expression))
    homer_upset
  })
  dev.off()

Hope it helps others as well

vidaletal avatar Jun 02 '20 10:06 vidaletal

My UpSet plot wasn't displayed in my Sweave document because of the first blank page. I wasn't sure how to use the onefile = FALSE trick in this context. Fortunately a workaround was merged in PR #101. You can now set the argument newpage = FALSE when printing an upset object.

Below is a reproducible example. The plot displays with newpage = FALSE, but if you change it to newpage = TRUE (the default), it disappears from the output PDF.

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<upset, fig=TRUE>>=
library(UpSetR)
movies <- read.csv(system.file("extdata", "movies.csv", package = "UpSetR"),
                   header = TRUE, sep = ";")
upsetPlot <- upset(movies, nsets = 7, nintersects = 30, mb.ratio = c(0.5, 0.5),
                   order.by = c("freq", "degree"), decreasing = c(TRUE,FALSE))
print(upsetPlot, newpage = FALSE)
@

\end{document}

jdblischak avatar Sep 21 '20 19:09 jdblischak