labeling/ coloring elements/segments of a linnet object

84 views Asked by At

I have 3 related questions for plots in spatstat:

  1. How do I label the segment of a linnet. for example just the id of the element
  2. How do I label co-variate attached to segment of linnet on a plot
  3. How to control width of an segment of linnet in a plot based on: a covariate or for example I want the thickness of the segment proportional to number of points realized on that segment from a point process on a network. So if a process generates 10 points on a line segment and 5 points on second segment, I would like to plot first segment twice wider than second segment.

I found examples in the book - Spatial Point Patterns - but they indicate use of image or kernel density to control the width of a segment. I am using linfun for a inhomogenous process and I did not find a method to color or control line width in my plot or to label the plot.

An example of small square:

library(spatstat)

v<-ppp(x=c(50,100,100,50), y=c(50,50,100,100),c(0,150), c(0,150)) #vertices
edg<-matrix(c(1,2,3,4,2,3,4,1), ncol=2) #edges
L<-linnet(v, edges=edg) #create a linnet

z<-c(11,22,33,44) # create covariate
Zfun <- linfun(function(x,y,seg,tp) { seg }, L)

plot(Zfun)

# I added some marks
marks(x) <- runif(npoints(x), 3, 4)

Thank you

1

There are 1 answers

3
Adrian Baddeley On BEST ANSWER

You can do everything by creating a suitable function of class linfun.

As an example, take the network L <- simplenet.

For question 1:

f <- linfun(function(x,y,seg,tp) { seg }, L)
plot(f)

The function f returns the segment ID number of the segment containing the specified point. This number runs from 1 to nsegments(L).

For question 2, suppose you have a vector Z giving the value of a covariate for each segment of the network (assuming the covariate value is constant on each segment). I'll take the example Z <- runif(nsegments(L)). Then

 g <- linfun(function(x,y,seg,tp) { Z[seg] }, L)
 plot(g)

For question 3,

 plot(g, style="width")

See help(plot.linfun) and help(plot.linim) (basically plot.linfun converts the function to a pixel image, and then calls plot.linim).