title: xyplot legend configuration
body: <p>It's my first time in here, so I hope not to do it wrong.</p>
  
  <p>I have a database of different measures of wood moisture content in different species as well as various index. These measures have been taken every two hours for six months.</p>
  
  <p>I'm trying to make a script that can be used in different locations. So far I managed to make the graph look ok, but with the legend I'm stuck.
  To make the axis I had to combine line date and hour, because I only wanted the ticks every Friday at 00:00.</p>
  
  <p>My problems appeared when I tried to make custom lines with specific colors and different shapes and then tried to make the legend. The colors don’t match the graph because I have changed the colors, but they are not changed in the legend. I also changed the order of the names that appear in the legend but the colors are still the default ones and don’t change with the name. When I try to do it manually with key, the line colors are always black, and also none is dotted.</p>
  
  <p>I have corrected the plot in paint, yes really shameful, but I needed to deliver it. But I need to do it more times so I’m trying to find a final solution. I have found that there is a bug in a post, and propose a manual way, but I’m not sure I can do it that way… so if any one knows how can I do it in a simpler way.</p>
  
  <p>So far my tries have been:</p>
  
  <p>a)  The default colors and organization</p>
  
  <pre><code>grafico_juan &lt;- read.table("C:/Users/JFG/Desktop/graf_juan2.txt", header=TRUE, sep="\t", na.strings="NA",dec=",", strip.white=TRUE)
  library(relimp, pos=14)
  library(lattice, pos=15)
  library(grid, pos=15)
  str(grafico_juan)
  grafico_juan[, "Date"] &lt;- as.Date(as.character(grafico_juan[, "Date"]), format = "%d.%m.%y")
  str(grafico_juan)
  grafico_juan[, "D.T"] &lt;- as.POSIXct(grafico_juan$D.T, format = "%d.%m.%y %H:%M:%S")
  str(grafico_juan)
  
  day=format(grafico_juan$D.T,"%a")
  data.frame(grafico_juan,day)
  #para seleccionar la parte que me hace falta para los puntos y las líneas
  grafico_juan2&lt;-subset(grafico_juan, subset = (Time == "00:00:00") &amp; (day == "vie"), selct= Date:PRMMTC)
  grafico_juan3&lt;-subset(grafico_juan, subset = (Time =="00:00:00"),select = Date:PRMMTC)
  data.frame(grafico_juan)
  str(grafico_juan2)
  str(grafico_juan3)
  xyplot(CSC + EUC + PCC + PLC + PRC + PRMMTC + PSC ~ D.T, type="l", cex=1, xaxt="n", auto.key=list(space="top",border=TRUE, columns=7, lines= T, points = F), par.settings = list(superpose.line = list(lwd=2)), scales=list(x=list(at=grafico_juan2$D.T, labels=format(grafico_juan2$D.T,"%d/%m"),rot=0, cex = 1, relation='free'), y=list(at= seq(from=2,to=nrow(grafico_juan), by=1),tick.number=52, rot=0, cex = 1, relation='free')), abline = list(h = 3:60, v = grafico_juan2$D.T, col = "grey"), data=grafico_juan, xlab="DATE (dd/mm)", ylab="MC (%)")
  </code></pre>
  
  <p>b)  Changing order and color</p>
  
  <pre><code>xyplot(CSC + EUC + PCC + PLC + PRC + PRMMTC + PSC ~ D.T, 
    type="l",col=c("green", "turquoise" ,"blue" , "green4", "deeppink",
    "black","red"),lty=c(1,1,1,1,1,1,3), cex=3, xaxt="n", 
    auto.key=list(space="top",border=TRUE, columns=7, lines= T,
    points = F, text=c("PL", "PS", "PR", "PC", "PRMMT", "CS", "EU")), 
    par.settings = list(superpose.line = list(lwd=2)), 
    scales=list(x=list(at=grafico_juan2$D.T, 
    labels=format(grafico_juan2$D.T,"%d/%m"),rot=0, cex = 1, 
    relation='free'), y=list(at= seq(from=2,to=nrow(grafico_juan), 
    by=1),tick.number=52, rot=0, cex = 1, relation='free')),
    abline = list(h = 3:60, v = grafico_juan2$D.T, col = c("grey")), 
    data=grafico_juan, xlab="DATE (dd/mm)", ylab="MC (%)")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/MITtP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MITtP.png" alt="enter image description here"></a></p>
  
  <p>c)  Doing it as a as.layer and using key insted of auto.key I still have the same problem, because it doesn't colour the lines nor put one dotted.</p>
  
  <pre><code>a&lt;-xyplot(CSC + EUC + PCC + PLC + PRC + PRMMTC + PSC ~ D.T, type="", cex=3, xaxt="n", key= list(text=list(levels=c("PL", "PS", "PR", "PC", "PRMMT", "CS", "EU")), lines= TRUE, border=TRUE, columns=7, fill=c("green4", "red", "deeppink","blue",  "black", "green", "turquoise")) , par.settings = list(superpose.line = list(lwd=2)), scales=list(x=list(at=grafico_juan2$D.T, labels=format(grafico_juan2$D.T,"%d/%m"),rot=0, cex = 1, relation='free'), y=list(at= seq(from=2,to=nrow(grafico_juan), by=1),tick.number=52, rot=0, cex = 1, relation='free')), abline = list(h = 3:60, v = grafico_juan2$D.T, col = c("grey")), data=grafico_juan, xlab="DATE (dd/mm)", ylab="MC (%)")
  
  b&lt;-xyplot(PLC ~ D.T, type="l",col= "green4" , cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  c&lt;-xyplot(PSC ~ D.T, type="l",col= "red" , cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  d&lt;-xyplot(PRC ~ D.T, type="l",col= "deeppink" , cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  e&lt;-xyplot(PCC ~ D.T, type="l",col= "blue" , cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  f&lt;-xyplot(PRMMTC ~ D.T, type="l",col= "black" , cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  g&lt;-xyplot(CSC ~ D.T, type="l" ,col= "green", cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  h&lt;-xyplot(EUC ~ D.T, type="l",col= "turquoise" , lty=3 ,cex=1, xaxt="n", auto.key=FALSE, par.settings = list(superpose.line = list(lwd=2)), data=grafico_juan, xlab="", ylab="")
  library(latticeExtra)
  a + as.layer(b) + as.layer(c) + as.layer(d) + as.layer(e) + as.layer(f)  + as.layer(g) + as.layer(h) 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/EJQCw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EJQCw.png" alt="enter image description here"></a></p>
  
  <p>The ideal one should be like this last picture but with the correct legend.</p>
  
  <p>Not sure if you need the data, but I provide part of it because I can't put too many characters, <code>D.T</code> is column <code>Date</code> and column <code>Time</code> in the same column.</p>
  
  <pre><code>Date            Time           D.T         EUC     PLC  PCC PSC PRC CSC PRMMTC
  12.03.15     14:00:00   12.03.15  14:00:00  11      9,3 6,8 9,1 9,6 3   6
  12.03.15     16:00:00   12.03.15  16:00:00  11,2    9,3 6,6 9,2 9,2 8,9 6,6
  12.03.15     18:00:00   12.03.15  18:00:00  11,7    9,7 6,6 9,6 9,6 9,2 7,4
  12.03.15     20:00:00   12.03.15  20:00:00  11,6    9,6 6,5 9,6 9,5 9,1 7,6
  12.03.15     22:00:00   12.03.15  22:00:00  11,6    9,6 6,5 9,6 9,6 9,1 7,6
  13.03.15     00:00:00   13.03.15  00:00:00  11,7    9,7 6,6 9,6 9,6 9,2 7,7
  13.03.15     02:00:00   13.03.15  02:00:00  11,8    9,8 6,6 9,6 9,6 9,2 7,7
  13.03.15     04:00:00   13.03.15  04:00:00  11,7    9,8 6,6 9,6 9,8 9,2 7,7
  13.03.15     06:00:00   13.03.15  06:00:00  11,7    9,7 6,6 9,7 9,7 9,2 7,7
  13.03.15     08:00:00   13.03.15  08:00:00  11,9    9,8 6,7 9,8 10  9,3 7,9
  13.03.15     10:00:00   13.03.15  10:00:00  11,7    9,8 6,6 9,8 9,8 9,2 7,7
  13.03.15     12:00:00   13.03.15  12:00:00  11,7    9,9 6,9 9,9 10  9,3 7,7
  13.03.15     14:00:00   13.03.15  14:00:00  11,9    10  6,9 9,9 10,1 9,4 7,7
  13.03.15     16:00:00   13.03.15  16:00:00  11,8    10  6,9 10  10,2 9,3 8
  </code></pre>