[R] Spatstat - problem with which.marks and as.pp

Rolf Turner rolf.turner at xtra.co.nz
Tue Dec 6 02:45:05 CET 2011

Basically the problem is that you have a *VERY* old version of spatstat.

Comments interpolated below.

On 05/12/11 21:52, karajamu wrote:
> I forgot to change the header, so I guess no one read my mail. That's why I'm trying it again...
>> Hello everbody,
>> I am new to this mailing list and hope to find some help.
>> I'm trying to get into the spatstat package and encountered two problems. First a graphical one:
>> There is an example dataset called "finpines" which has several marks (http://www.oga-lab.net/RGM2/func.php?rd_id=spatstat:finpines)
>> When I pass the given code from the website to R
>>      data(finpines)
If you were using the latest version of "spatstat" you wouldn't need to 
do this any more.
The data are now lazy-loaded.  See latest.news().
>> plot(unmark(finpines), main="Finnish pines: locations")
>> plot(finpines, which.marks="height", main="heights")
>> plot(finpines, which.marks="diameter", main="diameters")
>> I get the warning
>> Warnmeldung:
>> In symbols(c(-1.993875, -1.019901, -4.914071, -4.469962, -4.303847,  :
>>    "which.marks" ist kein Grafikparameter
>> Something like "which.marks" is not a graphic parameter; and the plots for height and diameter show now differences.
The version of spatstat that you are using must hail from a time prior to
when the argument "which.marks" was added to plot.ppp().

>> Furthermore, I  want to create a ppp with several marks, but I did not figure out how this works.
>> Trying
>> X<- as.ppp(mydata, owin(c(174, 178), c(29, 33)))
>> just gives the error
>> Error in as.ppp(mydata, owin(c(174, 178), c(29, 33))) :
>>    X must be a two-column or three-column data frame
>> The data set looks something like
>> Date   X   Y    Mar1    Mar2    Mar3
>> 1.1.    4   3     50       6          A
>> 2.1.    2   1     40       9          A
>> 3.1.    5   8     35       12        B
>> But how can I integrate two or more marks in a three-column data frame, when two columns are already needed for the X and Y coordinates?

Presumably you want "X" and "Y" to be the x and y coordinates of the 
points of
the pattern, respectively.  In which case they must be the ***first 
two*** columns
of the data frame.  (Not the second and third!)

As you have written "mydata", the first "Date" (the first column) will 
be of mode
"character", which will cause as.ppp() to throw an error.  I.e. it will 
try to take "Date"
as the x coordinates (and "X" as the y coordinates) and since "Date" is 
not numeric,
it will give up in disgust.  When I do

     X <- as.ppp(mydata, owin(c(174, 178), c(29, 33)))

(using the bit of "mydata" that your email showed) I get the error

     Error: is.numeric(x) is not TRUE

(as expected).  Of course I do not get the error that you got, which 
would have
been thrown by as.ppp() waaaayyyy back, when marks had to be *vectors* and
data frames of marks weren't allowed for.

Bottom line:  Update your version of spatstat.


         Rolf Turner

More information about the R-help mailing list