[R-sig-Geo] plot raster: how to eliminate surrounding white space?

Oscar Perpiñan oscar.perpinan at gmail.com
Wed Aug 28 01:08:20 CEST 2013


Hello,

I think this question asked for the same problem:
http://stackoverflow.com/questions/17214469/r-crop-raster-data-and-set-axis-limits

My proposal was to use raster::spplot or rasterVis::levelplot.

Best,

Oscar
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan


2013/8/27 Agustin Lobo <alobolistas at gmail.com>:
> Michael,
>
> On Tue, Aug 27, 2013 at 3:37 PM, Michael Sumner <mdsumner at gmail.com> wrote:
>> I don't get what you mean by "rectangles are closer", but maybe modify
>> the aspect ratio?
>> plot(a,axes=FALSE,legend=FALSE, asp = 0.2)
> No, that distorts the image. The plot of the actual image is correct.
> What I want is to reduce the extent of the large white area around the
> image. The shape of the white area
> is not proportional to the shape of the image, it is a much wider rectangle.
>
>> Otherwise, you can control the margins around each plot directly with
>> a bit of mixing old-school and new:
>> par(mar = c(0.1, 0.1, 0.1, 0.1), mfrow = c(2,2))
>> for (i in 1:4) plot(a[[i]], axes=FALSE,legend=FALSE, asp = 0.2)
>> I don't think you can control the par run by raster's plot function
>> directly, but if you stop it setting up the whole page like this it
>> respects each panel it seems.
>>
> Reducing the margins with par() is not enough, the big issue is the
> large white space surrounding each image.
> The trick seems to be making the plotting area so that it is more
> proportional to the shape of the image.
> Actually, based on your suggestion, this is quite close to what I need:
> par(mar = c(0.1, 0.1, 0.1, 0.1), mfrow = c(1,4))
> for (i in 1:4) plot(a[[i]], axes=FALSE,legend=FALSE, asp = 1)
>
> But a more general solution would be better.
>
> Thanks
> Agus
>
>
>
>> On Tue, Aug 27, 2013 at 11:15 PM, Agustin Lobo <alobolistas at gmail.com> wrote:
>>> I have raster images with many more rows than columns, i.e
>>> require(raster)
>>> a <- raster(matrix(200,ncol=256,nrow=3171))
>>> extent(a) <- c(0,256,0,3177)
>>>
>>> and get too much blank space at plotting:
>>>
>>> plot(a,axes=FALSE,legend=FALSE)
>>>
>>> in particular if I want to display several bands in the same plot:
>>> a <- stack(a,a*2,a/2,a*3)
>>> plot(a,axes=FALSE,legend=FALSE)
>>>
>>> Is there a way to optimize the plot so that rectangles are closer?
>>>
>>> Thanks
>>>
>>> Agus
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>>
>> --
>> Michael Sumner
>> Hobart, Australia
>> e-mail: mdsumner at gmail.com
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list