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

Agustin Lobo alobolistas at gmail.com
Tue Aug 27 19:01:19 CEST 2013


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



More information about the R-sig-Geo mailing list