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

empty first page in pdf output #90

Open
ChristofferFlensburg opened this issue Sep 11, 2017 · 8 comments
Open

empty first page in pdf output #90

ChristofferFlensburg opened this issue Sep 11, 2017 · 8 comments

Comments

@ChristofferFlensburg
Copy link

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

@JakeConway
Copy link
Member

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

@ChristofferFlensburg
Copy link
Author

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.

@alanocallaghan
Copy link
Contributor

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...

@mcbg
Copy link

mcbg commented Dec 7, 2017

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

@reesese
Copy link

reesese commented May 18, 2018

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.

@ChristofferFlensburg
Copy link
Author

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

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

@vidaletal
Copy link

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

@jdblischak
Copy link

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants