title: Building an HISTOGRAM with GGPLOT2: StatBin requires a continuous x variable the x variable is discrete
body: <p>I am sorry for the apparently basic question, but I tried hard, searched online as well, still stuck though. 
  These are the data: </p>
  
  <pre><code>temp &lt;- data.frame(mean=seq(1, 200, by=2), 
                   sd=seq(1, 200, by=2))
  
  
  normv &lt;- function( n , mean , sd ){
    out &lt;- rnorm( n*length(mean) , mean = mean , sd = sd )
    return( matrix( out , , ncol = n , byrow = FALSE ) )
  }
  
  
  set.seed(1)
  normv( 5 , temp$mean , temp$sd ) # 5 variables, from  V1 to V5
  mydata &lt;- as.data.frame(normv( 5 , temp$mean , temp$sd ))
  </code></pre>
  
  <p>And this is the loop to build 3 explorative graph on "mydata"</p>
  
  <pre><code>require(ggplot2)
  require(car)
  pdf(paste("Explore",1,".pdf",sep=""))
  layout(matrix(c(1,2,3,3), 2, 2, byrow = FALSE))
  lst1&lt;- lapply(names(mydata),function(i) 
  {
    print (
      ggplot(mydata, aes(i)) +
        geom_histogram(aes(y = ..density..),
                       fill = 'yellow',
                       alpha = 0.7,
                       col = 'black') +
        geom_density(colour="blue", lwd = 1, fill="lightyellow", alpha=0.5) +
        stat_function(fun = dnorm, 
                      args = list(mean = mean(mydata[,i], na.rm=T), sd = sd(mydata[,i], na.rm=T)), 
                      lwd = 1, 
                      col = 'red') +
        geom_vline(xintercept = mean(mydata[,i], na.rm=TRUE),col="lightblue", lty=1, lwd = 1) +
        geom_vline(xintercept = median(mydata[,i], na.rm=TRUE),col="purple", lty=2, lwd = 1) +
        theme_bw() +
        labs(title="Blue Line: Mean, Purple Line: Median") +
        theme(axis.text.x=element_text(size=14), axis.title.x=element_text(size=16),
              axis.text.y=element_text(size=14), axis.title.y=element_text(size=16))
          )
  
  
    qqnorm(mydata[,i], axes=FALSE)
    Boxplot(mydata[,i], 
            labels=rownames(mydata), id.n=Inf,
            col="royalblue",
            axes=TRUE,
            ylab=i,
            horizontal=FALSE)
  })
  </code></pre>
  
  <p>A Mock-up of the final Image I would like to get is as follows: 
  <a href="https://i.stack.imgur.com/6Dfel.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Dfel.png" alt="enter image description here"></a>
  Note that if I run the geom_histogram outside the loop it works fine, and when I exclude GGPLOT and use basic R for histogram, that works fine too. However, when I run the loop, I am still getting the error: </p>
  
  <pre><code>Error: StatBin requires a continuous x variable the x variable is discrete. Perhaps you want stat="count"? 
  </code></pre>
  
  <p>Note also that the difference between histogram and bar plot is crystal clear to me, in this case data are obviously continuous and NOT discrete, in facts I need an histogram. For academic purposes I have also tried to switch to geom_bar: I get rid of the error, but the resulting plot (as expected) does not make sense. </p>
  
  <p>Any help is greatly appreciated</p>