Nesting error

Asked

Viewed 73 times

1

I need to make a graph in the concatenated R, are 4177 iterations, I’m using ggplot2, but is giving the error below:

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Error during wrapup: evaluation nested too deeply: infinite recursion / options(expressions=)?

#geradora de dados sintéticos (triangulos)
#argumentos: numero de poligonos desejados, numero de vertices
gera_poligonos = function(numero_objetos, numero_vertices){
  dados = NULL
  for(i in 1:numero_objetos) dados[[i]] = matrix(rnorm(numero_vertices*2), ncol = 2)
  return(dados)
}  
#Funcao que plota os poligonos desejados (neste caso triangulos)
plot_poligono <- function(poligono){
  numero_vertices = nrow(poligono[[1]])
  g = ggplot()
   if(numero_vertices == 3){
    for(i in 1:length(poligono)){
       g = g + geom_polygon(data = data.frame(poligono[i]), aes(x = X1, y =      X2), colour="black", fill = NA)
    }
    return(g)
 }
  else print("Insira um poligono de tres vertices")    
}

#
teste = gera_poligonos(4177, 3)
plot_poligonos(teste)
  • 1

    Correct your spelling mistakes, arrange and organize your text, post the code (even if it is entire) through the "code" tab and put in hide code, will help your question to be answered and avoid down votes.

  • 1

    Wagner, this error is very general, it is impossible to give any suggestion without seeing the code. At the very least you should post the line that gives the error, but still it will be difficult to understand the problem. Investigate your code and try to reduce it to a minimum reproducible example, with less data, less manipulation, etc., but that generates the error. Otherwise I don’t think we can help you.

  • I edited, I put the simplest code I could, I thought it was a specific mistake. Thank you guys.

1 answer

3


You can do it as follows, instead of adding layers to your chart. The parameter group in the ggplot makes it a graph p/ each group, without the need to add layers to the graph.

teste = gera_poligonos(4177, 3)
names(teste) = 1:length(teste)
k <- plyr::ldply(teste, function(x) data.frame(x))
g <- ggplot(k, aes(x = X1, y = X2, group = .id)) + geom_polygon(colour = "black", fill = NA)
g

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.