[R] Wireframe plot inside a function

George Trojan - NOAA Federal george.trojan at noaa.gov
Fri Apr 21 17:27:20 CEST 2017


Consider the following example:

library("kdecopula")
library("mvtnorm")

pobs <- function(x) rank(x) / (length(x) + 1)

n <- 1000

sigma1 <- diag(x = 1, 2, 2)
x1 <- rmvnorm(n, sigma = sigma1)
xx1 <- apply(x1, 2, pobs)
cop1 <- kdecop(xx1)

eps <- 0.8
sigma2 <- matrix(c(1, eps, eps, 1), ncol = 2)
x2 <- rmvnorm(n, sigma = sigma2)
xx2 <- apply(x2, 2, pobs)
cop2 <- kdecop(xx2)

x11()
plot(cop1, main = "cop1 main")
x11()
plot(cop2, main = "cop2 main")

cplot <- function(cop1, cop2) {
  x11()
  plot(cop1, main = "cop1 function")
  x11()
  plot(cop2, main = "cop2 function")
}

cplot(cop1, cop2)

cat("Press <Enter> to quit")
readLines(file("stdin"), n
​ ​
=
​ ​
1)
quit()

When I run it with Rscript all four x11 windows pop up, however the one
that should display "cop1 function" is blank, the wireframe is not plotted.
This is R 3.3.1, on Fedora 20.
I see similar behaviour on Fedora 24, R 3.3.3 when I run the code from
RStudio (the most recent one).

George

	[[alternative HTML version deleted]]



More information about the R-help mailing list