PhanstielLab / plotgardener

https://phanstiellab.github.io/plotgardener/
Other
299 stars 28 forks source link

annoYaxis makes a new page when writing to PDF when axisLine = FALSE #91

Closed ksmetz closed 1 year ago

ksmetz commented 1 year ago

Hey plotgardeners! 🌱

I noticed what appears to be a small bug in the annoYaxis function, that causes it to re-plot on a new page when writing to PDFs.

The behavior appears to be similar to when you run pagePlotRemove or pageGuideHide (or at least how they used to behave, I haven't tested them in a PDF recently), where it saves the current plots to one page and then makes a new page with the change on it. I think this may be specifically related to the axisLine = FALSE default setting, because on the pages it will first show the y-axis with the line, and on the second page the line will be removed - although I haven't poked around the code itself to be sure yet.

This can currently be worked around by just drawing the axisLine with axisLine = TRUE. If you aren't doing a survey plot you can also manually trim the PDF to the final page after producing it. That said I wanted to post about it in case it wasn't the intended behavior, since it could be problematic if you really wanted to have a line-less y-axis in a survey plot I guess?

Here's a sample PDF where you can see it in action. This is the general structure of my script:

### Make page --------
pageCreate(...)

### Set parameters --------
p <- pgParams(...)

### Plot Hi-C --------
hicA = plotHicRectangle(...)
hicT = plotHicRectangle(...)

### Plot Hi-C legends --------
annoHeatmapLegend(plot = hicA, ...)
annoHeatmapLegend(plot = hicT, ...)

### Plot contacts --------
Z = ceiling(max(cluster1$`A`, cluster2$`A`))
arcA1 = plotPairsArches(data = cluster1, 
                        archHeight = "A", ...)
arcA2 = plotPairsArches(data = cluster2, 
                        archHeight = "A", ...)
annoYaxis(arcA1, at = seq(0, Z, by=2))

Z = ceiling(max(cluster1$`T`, cluster2$`T`))
arcT1 = plotPairsArches(data = cluster1, 
                        archHeight = "T", ...)
arcT2 = plotPairsArches(data = cluster2, 
                        archHeight = "T", ...)
annoYaxis(arcT1, at = seq(0, Z, by=2))

### Plot labels --------
plotText(label = "MCF10A", ...)
plotText(label = "MCF10AT1", ...)
plotText(label = "cluster 1", ...)
plotText(label = "cluster 2", ...)

### Plot genes --------
geneA = plotGenes(...)
geneT = plotGenes(...)

### Genome annotations --------
annoGenomeLabel(...)
annoGenomeLabel(...)

And here is the output: Ghule2023-MicroC-HLB_observed-c12arches.pdf

You can see how the PDF has everything up to the first annoYaxis on page 1 (with a vertical y-axis line), then everything up to the second annoYaxis on page 2 (first axis lost its vertical line but second has one), then to the end on page 3 (neither axes have a vertical line).

nekramer commented 1 year ago

Hi Katie!!

Thank you so much for picking out this bug. You are correct and this wasn't the intended behavior. I went back and updated how we created the yaxis grobs before drawing them, which removes the re-drawing and hence extra page creation. This should be fixed in Release version 1.6.3 and devel version 1.7.4!

Nicole