Nesting error

1

I need to make a graph in concatenated R, it's 4177 iterations, I'm using ggplot2, but it's 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)
    
asked by anonymous 10.05.2016 / 06:12

1 answer

3

You can do the following, instead of adding layers to your chart. The group parameter in ggplot causes a graph to be built for each group, without the need for you 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

    
10.05.2016 / 16:21