File: plot.msden.R

package info (click to toggle)
r-cran-sparr 2.3-16-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' @rdname plotsparr
#' @method plot msden
#' @export
plot.msden <- function(x, what = c("z", "edge", "bw"), sleep = 0.2, override.par = TRUE, ...){
  wha <- what[1]
  
  ellip <- list(...)
  if(is.null(ellip)) ellip <- list()
  if(is.null(ellip$box)) ellip$box <- FALSE
  if(is.null(ellip$ribargs)) ellip$ribargs <- list(box=TRUE)
  
  if(wha=="z"){
    lst <- x$z
  } else if(wha=="edge"){
    lst <- x$q
    if(is.null(lst)) stop("no edge correction present in multi-scale density object")
  } else if(wha=="bw"){
    lst <- x$him
    if(is.null(ellip$zlim)) ellip$zlim <- range(lapply(lst,range))
  } else {
    stop("invalid 'what'")
  }
  
  if(override.par){
    oldpar <- par(no.readonly = TRUE)
    on.exit(par(oldpar))
    par(mfrow=c(1,1),mar=rep(2,4))
  }
  
  hv <- as.numeric(names(lst))
  for(i in 1:length(lst)){
  	dev.hold()
    ellip$x <- lst[[i]]
    ellip$main <- paste("h0 =",round(hv[i],5))
    do.call("plot.im",ellip)
    plot(as.polygonal(Window(x$pp)),add=TRUE)
    axis(1)
    axis(2)
    box(bty="l")
    dev.flush()
    Sys.sleep(sleep)
  }
  invisible(NULL)
}