How to resolve the error Error in grid.Call.graphics(C_setviewport, vp, TRUE)

Viewed 2955

I have a function that generates many scatterplots. It's giving me an error that I haven't been able to find in this same context in researching the problem.

ExploreBiNumeric <- function(df){
  num_vars <- which(sapply(df, is.numeric))
  X <- df[names(num_vars)]
  for (i in 1:length(names(num_vars))){
    for(j in 1:length(names(num_vars))){
      if(i==j){}
      else{
      Y <- as.data.frame(cbind(X[i],X[j]))
      A <- colnames(Y[1])
      B <- colnames(Y[2])
      print(A)
      print(B)
      print(cor(Y))
      colnames(Y) <- c("i","j")
      print(ggplot(Y,aes(i,j)) + geom_point() + xlab(A) + ylab(B))
      }
    }
  }
  print(cor(X))
  print(corrplot(cor(X)))
  print(chart.Correlation(X,histogram=TRUE,pch=19))
  print(plot(X))
}

Error in grid.Call.graphics(C_setviewport, vp, TRUE) : non-finite location and/or size for viewport

I thought it could be caused by the labels. I tried passing them directly as xlab(colnames(X[i])) and ylab(colnames(X[j])) and that had the same result.

I also read that I should update the package ggsn. I did that.

0 Answers
Related