infotroph / ggplotTicks

Copy axes from bottom to top and left to right sides of a ggplot.
Other
9 stars 1 forks source link

Blank page when plotting to multipage PDF #2

Open infotroph opened 9 years ago

infotroph commented 9 years ago

Calling mirror.ticks() on figures with legends, while saving to PDF, if plotting to page 1, produces a PDF with an extra blank page.

# expect one page, get two: p. 1 blank, p. 2 has expected plot
pdf("cars-justoneplot.pdf")
plot(mirror.ticks(ggplot(mtcars,aes(wt,hp, color=carb))+geom_point()))
dev.off()

# expect two pages, get three: p.1 blank, rest as expected.
pdf("cars-twoplots.pdf")
plot(mirror.ticks(ggplot(mtcars,aes(wt,hp, color=carb))+geom_point()))
plot(mirror.ticks(ggplot(mtcars,aes(wt,carb, color=hp))+geom_point()))
dev.off()

# suppressing legend produces one page as expected. 
pdf("cars-justoneplot-nolegend.pdf")
plot(mirror.ticks(ggplot(
    mtcars,aes(wt,hp, color=carb))
    +geom_point()
    +theme(legend.position="none")))
dev.off()

Severity: Merely annoying.

This r-help thread from 2008 describes similar similar blank-page symptom and suggests this might come from different graphics functions fighting under the hood.

infotroph commented 8 years ago

Update: As of v0.1.0, all of the above examples still behave as reported if I call them as written above, but if I replace the deprecated mirror.ticks with the now-recommended mirror_ticks, all three examples behave as expected with no blank pages.

Updated severity: Maybe not even a problem? If anyone can trigger blank pages using mirror_ticks, please report how you did it.

infotroph commented 8 years ago

I suspect that the unwanted blank page happens inside a call to ggplotGrob: