r-lib / ragg

Graphic Devices Based on AGG
https://ragg.r-lib.org
Other
172 stars 24 forks source link

Rendering artefacts when using spplot #131

Closed janlimbeck closed 6 months ago

janlimbeck commented 1 year ago

When using ragg as the png rendering device I observe striping/visible borders e.g. when plotting spatial data using spplot from the sp package. I think under the hood lattice is used.

library(lattice)
library(sp)

trellis.par.set(sp.theme()) # sets bpy.colors() ramp
demo(meuse, ask = FALSE, echo = FALSE)

l2 <- list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(181300,329800), 
           scale = 400)
l3 <- list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(180500,329800), 
           scale = 500, fill=c("transparent","black"))
l4 <- list("sp.text", c(180500,329900), "0")
l5 <- list("sp.text", c(181000,329900), "500 m")

meuse.grid$g <- factor(sample(letters[1:5], 3103, replace=TRUE),
                       levels=letters[1:10])
meuse.grid$f <- factor(sample(letters[6:10], 3103, replace=TRUE),
                       levels=letters[1:10])
spplot(meuse.grid, c("f","g"), col.regions=bpy.colors(10))

With default rendering device: image

With ragg as rendering device: image

edzer commented 1 year ago

See also https://github.com/r-spatial/stars/issues/573 - for raster maps png usually does a better job. For pkgdown, you can turn using ragg off, see https://github.com/r-spatial/stars/blob/main/_pkgdown.yml

janlimbeck commented 1 year ago

Thanks for the response!

I am using the code within an RShiny application. I am aware that I can turn ragg off globally but would like to avoid that if possible due to the other benefits that ragg provides over the native rendering device.

Is there a way to select a specific rendering device for one individual RShiny plot? That would be an acceptable workaround for me.

tcwilkinson commented 1 year ago

One work-around for you may be to add a thin border of the same colour as the fill. Haven't tried it myself, and not sure if it has effect on performance -- but if lucky it may achieve what you want without playing with graphics devices etc...

See here: https://github.com/r-lib/ragg/issues/103#issuecomment-1458204888