[R] Character type and size using spatstats

p_connolly p_connolly at slingshot.co.nz
Thu May 15 04:25:55 CEST 2014


The spatstat package has hundreds of useful functions but I'm having
trouble understanding the intricate ways it does things.  I've read lots 
of
Rspatialcourse_CMIS_PDF Standard.pdf from here:
http://www.csiro.au/resources/pf16h but can't find what I need to know. 
I'm
particularly interested in how to set the plotting character and its
size in density plots.


   require(spatstat)
   load("CharacterSizeRData") # (attached to this message)
   ls()
[1] "all.win" "bb9"
   head(bb9)
    Col Row     ColN Concept Pch VinesJune VinesAug New Event
1    A  10 3.333333 Gold 4x   4        42       41   1  TRUE
8    A  16 3.333333 Gold 4x   4        42       41   1  TRUE
10   A  18 3.333333 Gold 4x   4        42       41   1  TRUE
11   A  19 3.333333 Gold 4x   4        42       41   1  TRUE
14   A  21 3.333333 Gold 4x   4        42       41   1  TRUE
18   A  24 3.333333 Gold 4x   4        42       34   8  TRUE
> 
## If I make a ppp class object from bb9, like so:
   ppp9A <- with(bb9, ppp(ColN, Row, range(ColN), range(Row), window = 
all.win,
                         marks = Concept))
## I can do a density plot:
   plot(density(ppp9A, 5, edge = FALSE, weights = bb9$New), main = 
"ppp9A")
## Adding to show the points:
   plot(ppp9A,  add = TRUE, cols = "red", maxsize = max(bb9$New)/20)
## works except that maxsize is ignored.
##
## If I make the ppp object like this:
   ppp9B <- with(bb9, ppp(ColN, Row, range(ColN), range(Row), window = 
all.win,
                          marks = New))
   plot(density(ppp9B, 5, edge = FALSE, weights = bb9$New), main = 
"ppp9B")
   plot(ppp9B,  add = TRUE, cols = "red", maxsize = max(bb9$New)/20)
## maxsize works how I intended.
##
## I tried to combine plotting character and size with a fancier use of 
marks
   ppp9C <- with(bb9, ppp(ColN, Row, range(ColN), range(Row), window = 
all.win,
                          marks = data.frame(New, Concept)))
## Then try
   plot(density(ppp9C, 5, edge = FALSE, weights = marks(ppp9C)$New), main 
= "")
   plot(ppp9C, add = TRUE, cols = "red", chars = 
levels(marks(ppp9C)$Concept),
        maxsize = max(marks(ppp9C)$New)/20)
## chars is ignored and no error message to complain or explain

What I wish to know is how to get plotting character and size
information displayed simultaneously.  I tried ways of specifying it
from bb9 dataframe instead of the ppp object, or specifying a fixed
value but it's always ignored.  Ideally, I'd like to customize the
plotting characters used, but getting the defaults to work would be a
start.

TIA

Patrick










More information about the R-help mailing list