简体   繁体   中英

Saving raster in R using png() and levelplot results in strange lines

I think I may have discovered a bug. I'm using levelplot in rasterVis, when I plot the rasters they show up fine in the raster window, however when I try and save them using png() the raster has lines through it.

library(raster)
library(rasterVis)
library(RColorBrewer)
col<-rasterTheme(region=brewer.pal(8,"YlOrRd"))
r<-raster(ncol=40,nrow=20)
r[] <- rnorm(n=ncell(r))
b<-"Title"

png(file=paste0(path,"\\",b,".png"), width=1800, height=1800, res=300)
plot<-levelplot(r,main=b,par.settings=col, margin=FALSE, scales=list(draw=FALSE))
print(plot)
dev.off()

In the plot window it shows up as it should: 在此输入图像描述

But saved using png() : 在此输入图像描述

I figured it out, the margins parameter needs to be in the form of a list. Resolves the lines in the images.

plot<-levelplot(r,main=b,par.settings=col, margin=list(draw=FALSE,scales=list(draw=FALSE)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM