Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R raster avoid white space when plotting

Tags:

plot

r

image

raster

I have an image and i want to plot only 100*100 square with left hand bottom corner at 0,0. when i use below commands. Why do i get a white space around my cropped image? how can i avoid it and ensure that I get exact 100*100 image?

If you want to repeat my example, you can use any image on line 1 (provided that the image is bigger than 100*100 pixels)

r <- raster("C:/Users/nnnn/Desktop/geo.jpg")
vector= getValues(r)
plot(r)
r


par(mar=c(0,0,0,0))
par(oma=c(0,0,0,0))
par(mai=c(0,0,0,0))
par(omi=c(0,0,0,0))
plot(r,xlim=c(0,100),ylim=c(0,100),legend=FALSE,axes=FALSE)

enter image description here

like image 348
user2543622 Avatar asked Nov 21 '22 20:11

user2543622


1 Answers

Aspect ratios are normally maintained for maps. You can use width/height when plotting to a file. You can resize the standard device manually, but you can also do this:

library(raster)
r <- raster(nrow=240, ncol=320)
values(r) <- 1:ncell(r)
dev.new(height=0.91*nrow(r)/50, width=1.09*ncol(r)/50)
plot(r, legend=FALSE)
like image 86
Robert Hijmans Avatar answered Jan 18 '23 12:01

Robert Hijmans