[R-sig-Geo] Plotting with stplot, mode="xy"

Rawlins, Barry G. bgr at bgs.ac.uk
Wed May 30 11:02:55 CEST 2012


Yes that solves it- thanks.

Re: title - yes I was thinking of a title other than the "time" and I will try subtitle or putting it into an axis label - that is fine.

Sorry, one further thing - trying to save the animation to a GIF with:

library(animation)
saveGIF(

stplot(sp_time_slice, animate=1,
col.regions=rainbow(11,start=0.0,end=0.66),cex=2,cuts=c(seq(r[1],r[2],length.out=11)))

)

The animated plot just goes back to the start and the GIF does not get saved - I assume this is because stplot is not in a loop which is what saveGIF appears to require to save an animation. Any ideas how I would resolve that? I tried:

out<-stplot(sp_time_slice,...

saveGIF
(
print(out)
)

But that was no good.

By the way - these data are soil moisture sensor data (15 minute intervals) from a hillslope responding to incident rainfall. I would be happy for you to use these as example data if that is useful to you. 

Best wishes, Barry

-----Original Message-----
From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] 
Sent: 30 May 2012 09:41
To: Rawlins, Barry G.
Subject: Re: [R-sig-Geo] Plotting with stplot, mode="xy"

with

> r= range(sp_time_slice at data$VMC) #[1] 20.7 36.8
> stplot(sp_time_slice, animate=1,
col.regions=rep(1,10),cex=2,cuts=c(seq(r[1],r[2],length.out=11)))

I don't see points dropping, do you?

On 05/30/2012 10:30 AM, Rawlins, Barry G. wrote:
> Edzer
> 
> Here is the data attached as an object and code to run it below:
> 
> load(file="sp_time_slice.RData")
> 
> range(sp_time_slice at data$VMC) #[1] 20.7 36.8
> 
> # so with narrow ranges (20 to 37) - some symbols dropped
> 
> stplot(sp_time_slice, animate=1, col.regions=rainbow(10,start=0.0,end=0.66),cex=2,cuts=c(seq(20,37,1.7)))
> 
> # with wider ranges (18, 38) all symbols plot
> 
> stplot(sp_time_slice, animate=1, col.regions=rainbow(10,start=0.0,end=0.66),cex=2,cuts=c(seq(18,38,2)))
> 
> I am also struggling to get a title to plot using either
> 
> lattice.options=list(main="Sensor Net volumetric moisture content (%)"))
> or 
> main=list(label="Sensor Net volumetric moisture content (%)")
> 
> Error in trellis.skeleton(formula = y2 ~ x2, cond = list(c(1L, 1L, 1L,  : 
>   formal argument "main" matched by multiple actual arguments
> In addition: Warning message:
> In seq.default(min(obj[[z]], na.rm = TRUE), max(obj[[z]], na.rm = TRUE),  :
>   first element used of 'length.out' argument
> 
> What would you use?

Well, that's a nice feature request -- I haven't given it much thought,
and main obviously is not allowed. You could use xlab="some title" or
sub="subtitle" to see something, but I agree it's not optimal; you'd
like to have time in subtitle when a main is given, right?

> 
> Barry
> 
> -----Original Message-----
> From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] 
> Sent: 30 May 2012 09:19
> To: Rawlins, Barry G.
> Subject: Re: [R-sig-Geo] Plotting with stplot, mode="xy"
> 
> Barry,
> 
> could you please provide me with a reproducible example that
> demonstrates that min/max values passed as extremes of cuts discards
> some points?
> 
> I cannot reproduce it with:
> 
>> library(sp)
>> loadMeuse()
>> m = meuse[1:4,]
>> m
>        coordinates cadmium copper lead zinc  elev       dist   om ffreq soil
> 1 (181072, 333611)    11.7     85  299 1022 7.909 0.00135803 13.6     1    1
> 2 (181025, 333558)     8.6     81  277 1141 6.983 0.01222430 14.0     1    1
> 3 (181165, 333537)     6.5     68  199  640 7.800 0.10302900 13.0     1    1
> 4 (181298, 333484)     2.6     81  116  257 7.655 0.19009400  8.0     1    2
>   lime landuse dist.m
> 1    1      Ah     50
> 2    1      Ah     30
> 3    1      Ah    150
> 4    0      Ga    270
>> spplot(m["om"], cuts=c(8,10,12,14),col.regions=bpy.colors())
>> spplot(m["cadmium"], cuts=c(2.6,8,11.7),col.regions=bpy.colors())
> 
> 
> On 05/30/2012 09:57 AM, Rawlins, Barry G. wrote:
>> Daniel and Edzer
>>
>> I managed to build the stplot.R function and get that working - so thanks for that. The "cut" argument works fine and the scale does not change now as the animation runs. For some reason I needed to make the bin range (min and max) wider than the range of the data to make sure all the xy locations plotted in every amimation (some were dropped otherwise)  - I am not sure why that would be the case.
>>
>> I will look for some instructions (presumably on other help lists) on how to build a package from the source as that is not something I have done before, but will be pleased to learn.
>>
>> Best wishes, Barry
>>
>>  
>> -----Original Message-----
>> From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Daniel Nüst
>> Sent: 29 May 2012 17:21
>> To: r-sig-geo at r-project.org
>> Subject: Re: [R-sig-Geo] Plotting with stplot, mode="xy"
>>
>> Am 29.05.2012 18:07, schrieb Edzer Pebesma:
>>> On 05/29/2012 04:03 PM, Rawlins, Barry G. wrote:
>>>> I can see a series of folders+files on the svn area - can you just give me some direction on how I get the source code? Were you suggesting I just take the code under R/stplot.R? And build a function from this?
>>> I was thinking about building and installing the R package from source,
>>> but that might be a bridge too far if you're not used to doing that.
>>>
>>> It might be easier to source the whole R/stplot.R file in your R session
>>> -- that should work as well.
>>
>> The svn also has http access, so
>>
>> source("https://svn.52north.org/svn/geostatistics/main/spacetime/R/stplot.R")
>>
>> should do just that.
>>
>> /Daniel
>>
>>>> -----Original Message-----
>>>> From: Edzer Pebesma [mailto:edzer.pebesma at uni-muenster.de] 
>>>> Sent: 29 May 2012 13:23
>>>> To: Rawlins, Barry G.
>>>> Subject: Re: [R-sig-Geo] Plotting with stplot, mode="xy"
>>>>
>>>> svn co https://svn.52north.org/svn/geostatistics/main/spacetime/
>>>>
>>>> will give you the updated source. Let me know if it works, otherwise
>>>> we'll try the CRAN route (CRAN seems a bit over-worked, lately, for
>>>> clear reasons, throwing NOTEs if you're uploading too frequent).
>>>>
>>>> I just noticed that the package DESCRIPTION file does not contain this
>>>> URL -- will modify.
>>>>
>>>>
>>>> On 05/29/2012 01:28 PM, Rawlins, Barry G. wrote:
>>>>> Many thanks Edzer - it is superb to have your help on such occasions.
>>>>>
>>>>> Checking CRAN - the latest version of spacetime appears to be 0.7-0 - does that mean I need to wait for 0.7-1 (which you refer to) to be released?
>>>>>
>>>>> I did not copy to the list because I was not sure this question was relevant to my problem.
>>>>>
>>>>> Best wishes, Barry
>>>>>
>>>>>
>>>>> -----Original Message-----
>>>>> From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Edzer Pebesma
>>>>> Sent: 29 May 2012 11:28
>>>>> To: r-sig-geo at r-project.org
>>>>> Subject: Re: [R-sig-Geo] Plotting with stplot, mode="xy"
>>>>>
>>>>> Hi Barry, the following should have worked:
>>>>>
>>>>> library(spacetime)
>>>>> loadMeuse()
>>>>> d = as.data.frame(meuse)[c("cadmium", "copper", "lead", "zinc")]
>>>>> x = STFDF(meuse, Sys.time()+1:4, stack(d))
>>>>> stplot(x, animate=1, col.regions=bpy.colors(),
>>>>>    cuts=c(1,10,100,1000,10000))
>>>>>
>>>>> but doesn't fix the legend with current spacetime on CRAN, as the 'cuts'
>>>>> argument was not passed on to spplot.
>>>>>
>>>>> spacetime 0.7-1 in subversion has this fixed.
>>>>>
>>>>> the 'col' argument needs to be called 'col.regions'.
>>>>>
>>>>> On 05/28/2012 06:34 PM, Rawlins, Barry G. wrote:
>>>>>> Hello
>>>>>>  
>>>>>> I am trying to plot some space-time data which encompasses 3654 time
>>>>>> intervals (15 mins each) at 84 sites.
>>>>>>  
>>>>>> I would like to animate these data and so I have used the following code
>>>>>> and my STFDF object is "sp_time":
>>>>>>  
>>>>>> colors.ten<-rainbow(10,start=0.0,end=0.66) # rainbow color scale
>>>>>> stplot(sp_time, mode="xy", animate=1, cuts=10, at=seq(5,55,5),
>>>>>> auto.key=T,col=colors.ten)
>>>>>>  
>>>>>> The first plot I see is this where the points are plotted in the correct
>>>>>> locations:
>>>>>>  
>>>>>> But, I wanted some bespoke rainbow colors which do not appear and I know
>>>>>> the z-range of the data is wider than that shown - the range is actually
>>>>>> between 6 and 44. When I run the animation the scale changes each time
>>>>>> but I would like it to be fixed so that each time slice has the same
>>>>>> scale. Any advice on how I can solve this? I have tried reading the help
>>>>>> pages on levelplot but to no avail.
>>>>>>  
>>>>>> Thanks, Barry
>>>>>>  
>>>>>>  
>>>>>>  
>>>>>>  
>>>>>>
>>>>>> -- 
>>>>>> This message (and any attachments) is for the recipient only. NERC
>>>>>> is subject to the Freedom of Information Act 2000 and the contents
>>>>>> of this email and any reply you make may be disclosed by NERC unless
>>>>>> it is exempt from release under the Act. Any material supplied to
>>>>>> NERC may be stored in an electronic records management system.
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> R-sig-Geo mailing list
>>>>>> R-sig-Geo at r-project.org
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>
>>>>
>>>
>>
>>
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list