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

Thomas Adams tea3rd at gmail.com
Tue Nov 18 19:34:23 CET 2014


Nuno,

I thought you might say that. I have used R with GRASS GIS, which
interfaces using the spgrass6 contributed package. I have analyzed some
pretty large GIS raster files, looking at radar precipitation data, and the
approach I suggested works well. The data imported into R using sp (the
basis for spgrass6) is an sp raster object. So, from the spgrass6 manual:

After loading R from the GRASS GIS terminal prompt, for example,

spear <- readRAST6(c("geology", "elevation.dem"), cat=c(TRUE, FALSE))

Try looking at this:

summary(spear)

 you can do this:

boxplot(spear$elevation.dem ~ spear$geology)

 or this, for instance :

hist(spear$elevation.dem)
meanx<-mean(spear$elevation.dem)
abline(v=meanx, col="red")

But, maybe I don't understand the problem??

Regards,
Tom


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]]



More information about the R-sig-Geo mailing list