[R-sig-Geo] Question on histograms from Raster and RasterVIS packages

Nuno Sá nunocesardesa at gmail.com
Tue Nov 18 20:03:15 CET 2014


Hello!

Yes, it sorted the problem but maybe not as we were expecting, you've
"liberated" me from the raster package 3% data limitation and now I can
work with it easily as a normal histogram.

Basically the trick that I got from the "readRAST6" function you suggested
is that it converts it into sp objects (SpatialGridDataFrame in this case i
guess). From here it is easy: all I need is to convert the rasters to an sp
object and from there I am back working with normal hist functions.

So, using the conversion: as(inputraster,"SpatialGridDataFrame") sorted it
out. The rest is history. I hope they update this method into the raster
package because there is no need to be limited to a 100 000 sample which is
usually kind of low for RS data.

Found a similar limitation on usdm package recently which chooses to
needlessly convert a whole raster into a data.frame before calculating VIF
between variables. For huge rasters, it would kill off the computer memory.
Because of that, I guess the authors also made a limit on the sample size
(which was not what was actually killing the computer memory)

Dr Greg

Yes, I think the rasterVIS package uses grid. maybe it can be inserted when
we call the histogram function, but making it do a vertical line might be
kind of complicated, I think just from looking to how it is called.

Thank you guys for the suggestions!!

I jump between them also, but making graphs is usually easy enough just
using R. anyway, it is so great to have all these awesome languages and
softwares linked together.

Best of luck for all!
Nuno


On 18 November 2014 18:38, Thomas Adams <tea3rd at gmail.com> wrote:

> Nuno,
>
> Possibly having a reproducible example would help. I do all my spatial
> analysis work starting from GRASS GIS and calling R from the GRASS prompt —
> this works very well.
>
> Tom
>
> On Tue, Nov 18, 2014 at 11:35 AM, Greg Snow <538280 at gmail.com> wrote:
>
>> Nuno,
>>
>> Does rasterVIS use base or grid graphics?
>>
>> The place I usually see the error that plot.new has not been called yet
>> is when trying to use a base graphics function to augment a plot created
>> using grid graphics.  I suspect that the plot created used grid graphics
>> and that is why abline is not working for you.
>>
>> There is a 'grid.abline' function in the grid package, though it does not
>> look like it would work easily for a vertical line, so you may need to dive
>> into the details of using grid in more detail, probably using the
>> grid.lines function.  There is also the gridBase package which helps grid
>> and base graphics play nicely together, though it could be a bit of
>> overkill for just adding a vertical line.
>>
>> On Tue, Nov 18, 2014 at 11:21 AM, Nuno Sá <nunocesardesa at gmail.com>
>> wrote:
>>
>>> Hey Thomas!
>>>
>>> Yes thanks, I know it works for the normal hist function which uses 3% of
>>> all data (mind I am talking about rasters) which I am not sure that is a
>>> good enough sample, I leave that question in the air
>>>
>>> The problem is it does not work in rasterVIS (which does use all the
>>> raster). The error it gives me is the following:
>>>
>>> > abline(v=m.rst,col="blue",lwd=2)
>>> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
>>>   plot.new has not been called yet
>>>
>>> Regards!!
>>> Thank you once again!
>>> Nuno
>>>
>>> On 18 November 2014 18:04, Thomas Adams <tea3rd at gmail.com> wrote:
>>>
>>> > Nuno,
>>> >
>>> > This works for me:
>>> >
>>> > > require(stats)
>>> > > set.seed(14)
>>> > > x <- rchisq(100, df = 4)
>>> > >
>>> > >
>>> > > hist(x)
>>> > > meanx<-mean(x)
>>> > > meanx
>>> > [1] 3.734162
>>> > > abline(v=meanx, col="red")
>>> >
>>> > Cheers!
>>> > Tom
>>> >
>>> > On Tue, Nov 18, 2014 at 10:56 AM, Nuno Sá <nunocesardesa at gmail.com>
>>> wrote:
>>> >
>>> >> Hello!
>>> >>
>>> >> My aim is to add a "Median" or a "Mean" line to an histogram plot in
>>> R.
>>> >>
>>> >> The problem is the following:
>>> >>
>>> >> The "hist" function from the raster package uses a maximum of 100 000
>>> >> values for generating the histogram but allows me to edit the plot,
>>> so I
>>> >> can easily add a line within the plot using abline.
>>> >>
>>> >> The "histogram" function in rasterVIS uses all my dataset but does not
>>> >> allow editing of the plot area, so I cannot use the abline function
>>> to add
>>> >> this line (or I do not know how to do it).
>>> >>
>>> >> If you have an alternative or a solution to work around this, I am all
>>> >> hears
>>> >>
>>> >> Thank you for any help in advance!
>>> >> Ciao!
>>> >> --
>>> >>
>>> >> Nuno César de Sá
>>> >> +351 91 961 90 37
>>> >>
>>> >>         [[alternative HTML version deleted]]
>>> >>
>>> >> _______________________________________________
>>> >> R-sig-Geo mailing list
>>> >> R-sig-Geo at r-project.org
>>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>> >>
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>>
>>> --
>>>
>>> Nuno César de Sá
>>> +351 91 961 90 37
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538280 at gmail.com
>>
>
>
>
>
>
>


-- 

Nuno César de Sá
+351 91 961 90 37

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list