Closed eliocamp closed 12 months ago
A more minimal example:
library(ggplot2)
library(ggpattern)
pattern_dots <- ggplot2::ggproto("GeomDots", ggpattern::GeomPolygonPattern)
ggplot2::update_geom_defaults(pattern_dots,
list(pattern = "circle",
colour = NA,
pattern_colour = "black",
pattern_fill = "black",
pattern_density = 0.3,
pattern_alpha = 1,
pattern_spacing = 0.02,
fill = NA
))
data <- expand.grid(lon = seq(0, 360, by = 2.5),
lat = seq(-90, 0, by = 2.5)) |>
transform(h = cos(lat*pi/180*3))
gg <- ggplot(data, aes(lon, lat)) +
geom_contour_filled(aes(z = h)) +
stat_contour_filled(aes(z = h),
breaks = c(-0.8, .4), fill = NA, geom = pattern_dots) +
coord_polar()
pdf("pdf.pdf")
plot(gg)
invisible(dev.off())
cairo_pdf("cairo.pdf")
plot(gg)
invisible(dev.off())
The evince
issue with alpha masks and pdf()
is a known bug in poppler
: https://github.com/coolbutuseless/ggpattern/issues/70
I've reported it upstream to both poppler
and a R Core team member
poppler
and won't make changes in pdf()
poppler
issue is still open and I still see it with evince
on my machine so maybe not fixed yet on their endI reproduce the firefox
issue too. Don't think I can do anything to speed up firefox's rendering of pdf files...
Instead of using R's alpha mask feature you can instead opt into using a rasterized fallback if you set options(ggpattern_use_R4.1_masks = FALSE)
. If may not look as pretty especially at low resolutions but it may avoid some of the issues you notice. In particular with the default resolution it appears to render faster in firefox
and I don't observe the visual bug in evince
.
options(ggpattern_use_R4.1_masks = FALSE)
pdf("pdf.pdf")
plot(gg)
invisible(dev.off())
Bug description
Patterns fail to render correctly in Evince and Firefox with pdf device.
Evince shows circular patterns with holes as a single square and firefox renders each individual dot very slowly. These problems go away by using cairo_pdf.
Minimal, reproducible example
This knitr document: