White-line artifacts in ggplot2 plots

Viewed 426

(Edit: now submitted as ggplot2 issue #4183.)

I'm not sure exactly what conditions cause this to happen, but here's a pretty small example derived from the real plot that I was working on when I ran into this:

library(ggplot2)

d = data.frame(x = seq(0, 2, len = 2500))
d$y = d$x^2

ggsave("~/plot.png", width = 3, height = 4, dpi = 90,
    ggplot(d) +
    geom_col(aes(x, y), width = max(diff(d$x))) +
    theme_bw() +
    theme(
        panel.border = element_blank(),
        panel.grid = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank()))

With ggplot2 3.3.2 on R 3.6.2 on Linux, I get this:

Output of the code above

How do I reliably avoid getting vertical white lines like the one at about x = 0.8 above?

1 Answers

ggplot has decreed this a won't-fix, but it can be worked around by increasing the width with something like geom_col(aes(x, y), width = max(diff(d$x)) * 1.05, position = "identity"):

New output

Related