I have 3 related questions for plots in spatstat:
- How do I label the segment of a linnet. for example just the id of the element
- How do I label co-variate attached to segment of linnet on a plot
- 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
You can do everything by creating a suitable function of class
linfun
.As an example, take the network
L <- simplenet
.For question 1:
The function
f
returns the segment ID number of the segment containing the specified point. This number runs from1
tonsegments(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 exampleZ <- runif(nsegments(L))
. ThenFor question 3,
See
help(plot.linfun)
andhelp(plot.linim)
(basicallyplot.linfun
converts the function to a pixel image, and then callsplot.linim
).