title: r - Add text to each lattice histogram with panel.text but has error "object x is missing"
body: <p>In the following R code, I try to create 30 histograms for the variable <code>allowed.clean</code> by the factor <code>zip_cpt</code>(which has 30 levels). </p>
  
  <p>For each of these histograms, I also want to add mean and sample size--they need to be calculated for each level of the factor <code>zip_cpt</code>. So I used <code>panel.text</code> to do this. </p>
  
  <p>After I run this code, I had error message inside each histogram which reads "Error using packet 21..."x" is missing, with..." (I am not able to read the whole error message because they don't show up in whole).  I guess there's something wrong with the object x. Is it because mean(x) and length(x) don't actually apply to the data at each level of the factor zip_cpt? </p>
  
  <p>I appreciate any help!</p>
  
  <pre><code>histogram(~allowed.clean|zip_cpt,data=cpt.IC_CAB1,  
        type='density',
        nint=100,
        breaks=NULL,
        layout=c(10,3),  
        scales= list(y=list(relation="free"),
                     x=list(relation="free")),
        panel=function(x,...) {
                               mean.values &lt;-mean(x)
                               sample.n &lt;- length(x)
                               panel.text(lab=paste("Sample size = ",sample.n))
                               panel.text(lab=paste("Mean = ",mean.values))
                               panel.histogram(x,col="pink", ...) 
                               panel.mathdensity(dmath=dnorm, col="black",args=list(mean=mean(x, na.rm = TRUE),sd=sd(x, na.rm = TRUE)), ...)})
  </code></pre>