I am using raster function as shown on lines below. My last line produces some output. That output has a line that says dimensions : 240, 320, 76800 (nrow, ncol, ncell)
. I would like reprint that image but say only first 200 rows and first 300 columns. How can I do that? The second last line below plots the entire image
f <- "pictures/image1-1421787394.jpeg"
f
r <- raster(f)
plot(r);
r
=============================update1
I did png(filename = '~/x.png');par(mar=rep(0, 4), xpd = TRUE, oma=rep(0, 4),bty='n') ; plot(r,xlim=c(0,200),ylim=c(0,200),legend=FALSE,axes=FALSE); dev.off()
to save the cropped image. I was able to get rid of the legend and axes and the black box. But the problem is that the saved image contains much more than cropped part - for example white part around the image. I want to save only the cropped part of the original (keep image size 200*200 pixels). Please let me know how to do that?
Moreover, how could i add a red square that corresponds to the above cropped part to the original image? I mean I would like to get a red square (only edges) on the top of the original image and then save this (original image+square) as a new image.
How could i do that?
update2++++++++++++++++++++++++++++++++++++++++++++++++
adding repeatable example to show what i mean by white background
the last line below plots cropped image. I want that image to be 100*100 as my xlim and ylim are 100. But i see a white background as shown in the example below. (you cannot see the background. But if you run the code on your machine and open the image, you will see it)
library(raster)
r <- raster(nrow=240, ncol=320)
values(r) <- 1:ncell(r)
plot(r)
plot(r,xlim=c(0,100),ylim=c(0,100),legend=FALSE,axes=FALSE,frame.plot=F)