title: Plot lme4 reordered Penicillin data with lattice
body: <p>I am reading the lme4 documentation book to learn how to analyze linear mixed-effects models. I am trying to reproduce all steps, but I have an issue when trying to plot the reordered Penicillin dataset as it appears in the section 8.2.2 Multiple Random Effects of this website (<a href="http://www.john-ros.com/Rcourse/lme.html" rel="nofollow noreferrer">http://www.john-ros.com/Rcourse/lme.html</a>) Figure link: <a href="http://www.john-ros.com/Rcourse/Rcourse_files/figure-html/unnamed-chunk-181-1.png" rel="nofollow noreferrer">http://www.john-ros.com/Rcourse/Rcourse_files/figure-html/unnamed-chunk-181-1.png</a></p>
  
  <p>So far, I have been able to reorder the data frame and plot the dots successfully with different shapes, but I am unable to link the dots for each sample in the right reordered way. They plot in the original order and the plot looks really messy.</p>
  
  <p>I have tried to look for the code for this plot online but I'm not able to locate it anywhere. I'm sorry in advance if this is a trivial question.</p>
  
  <p>Here you have the code I have written so far:</p>
  
  <pre><code>library(lme4)
  require(lattice)
  
  myPCH &lt;- 1:6
  myLTY &lt;- 1:6
  
  
  # Plotting only the dots in the right way
  xyplot(reorder(plate, diameter) ~ diameter, Penicillin,
         xlab="Diameter of growth inhibition zone (mm)",
         ylab = "Plate",
         groups=factor(sample,labels=as.character(unique(Penicillin$sample))),
         pch=myPCH, col=1:6,
         key =  list(columns=6,
                     text = list(as.character(unique(Penicillin$sample))),
                     points = list(pch=myPCH, col=1:6)),
         type = c("g","p"))
  
  
  # Adding the lines in the wrong order (Modified so that they have 
  # different styles
  xyplot(reorder(plate, diameter) ~ diameter, data=Penicillin,
         xlab="Diameter of growth inhibition zone (mm)",
         ylab = "Plate",
         groups=factor(sample,labels=as.character(unique(Penicillin$sample))),
         pch=myPCH, col=1:6,
         lty=myLTY,
         key =  list(columns=6,
                     text = list(as.character(unique(Penicillin$sample))),
                     points = list(pch=myPCH, col=1:6)),
         type = c("g","p","l"))
  
  
  # Trying to plot the dots and the lines separately with the 
  # "panel = function(x, y, groups,...)" lattice function 
  
  xyplot(reorder(plate, diameter) ~ diameter, data=Penicillin,
         groups=factor(sample,labels=as.character(unique(Penicillin$sample))),
         xlab="Diameter of growth inhibition zone (mm)",
         ylab = "Plate",
         key =  list(columns=6,
                     text = list(as.character(unique(Penicillin$sample))),
                     points = list(pch=myPCH, col=1:6)),
         panel = function(x, y, groups,...) {
  
         panel.xyplot(x, y,
                        pch=myPCH, col=1:6,
                        type = c("g","p"));
  
         panel.linejoin(x, y,
                          lty=myLTY, col=1:6,
                          type = c("g","l"))
         })
  
  
  sessionInfo()
  </code></pre>
  
  <p>I would like to plot, the points and the lines with different shapes as it is plotted in the original png picture I mentioned before.</p>
  
  <p>This is my sessionInfo():</p>
  
  <pre><code>R version 3.5.1 (2018-07-02)
  Platform: x86_64-apple-darwin15.6.0 (64-bit)
  Running under: macOS High Sierra 10.13.6
  
  Matrix products: default
  BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
  LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
  
  locale:
  [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] MEMSS_0.9-2     lattice_0.20-38 ggplot2_3.1.0   lme4_1.1-19     Matrix_1.2-15  
  
  loaded via a namespace (and not attached):
   [1] Rcpp_1.0.0       rstudioapi_0.9.0 magrittr_1.5     bindr_0.1.1      splines_3.5.1   
   [6] MASS_7.3-51.1    tidyselect_0.2.5 munsell_0.5.0    colorspace_1.4-0 R6_2.3.0        
  [11] rlang_0.3.1      minqa_1.2.4      plyr_1.8.4       dplyr_0.7.8      tools_3.5.1     
  [16] grid_3.5.1       gtable_0.2.0     nlme_3.1-137     withr_2.1.2      lazyeval_0.2.1  
  [21] assertthat_0.2.0 tibble_2.0.1     crayon_1.3.4     bindrcpp_0.2.2   purrr_0.2.5     
  [26] nloptr_1.2.1     glue_1.3.0       labeling_0.3     compiler_3.5.1   pillar_1.3.1    
  [31] scales_1.0.0     pkgconfig_2.0.2
  </code></pre>
  
  <p>Thank you very much for your help,</p>