0

I have produced a plot of a RasterLayer using gplot and rasterVis (a wrapper around gplot). In order to display the raster output at full resolution I have to set the gplot parameter maxpixels = 10000000. Although the raster resolution looks fine in R, when I try to write it to a file, the image is again downsampled to the standard resolution. Following the code I used:

png(paste0(pathAndFilename, ".png"))

gplot(myRaster, maxpixels = 10000000) +
    geom_raster(aes(fill = factor(value))) +
    scale_fill_manual(values=c(someColors), legendSpecs) +
    coord_equal() +
    labs(title = "SomeTitle", x = "Lng", y = "Lat")

dev.off()

Any help appreciated!

1 Answer 1

1

In the help of the png() function it says this:

png(filename = "Rplot%03d.png",
    width = 480, height = 480, units = "px", pointsize = 12,
    bg = "white", res = NA, family = "", restoreConsole = TRUE,
    type = c("windows", "cairo", "cairo-png"), antialias)

All parameters that have an equal sign and a value, have defaults in case you don't mention them explicitly. Set width and height to the correct numbers from the raster you want to print and you will not have any resampling.

You probably want something like this:

png(paste0(pathAndFilename, ".png"), width = ncol(myRaster), height = nrow(myRaster))

gplot(myRaster, maxpixels = 10000000) +
    geom_raster(aes(fill = factor(value))) +
    scale_fill_manual(values=c(someColors), legendSpecs) +
    coord_equal() +
    labs(title = "SomeTitle", x = "Lng", y = "Lat")

dev.off()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I already tried this, the resolution is fine then. But the font size of the title, legend etc is relatively smaller then. I'm unable to change this (not using par, nor are there any respective gplot arguments).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.