1

I've realized plots with lattice and I need to split my data to get a representation of different stations of a lake, with the line and the dots for each replicas made by each team have worked in this lake. I manage to do that, but the legend is formed by all of the team have worked in this exercise and present in my DB, not only by the ones which appear in my plot.

# Expression des données physico



###############################################
#Expression des données pour Cromwell

#Préparation du panel
panel.my <- function(...) {
  panel.superpose(...)
}

trellis.par.set(superpose.symbol=list(pch=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)),
                superpose.line=list(lty=c(1, 2, 3, 4, 5, 6, 7)))


#Graphique Temp avec lines
xyplot(prof~temp | lake * station,
       type=c("p", "l"),
       physico,
       subset=lake=="Crom",
       group=team,
       panel = panel.my, 
       xlim=c(6,15),
       ylim=c(10,-1),
       scales=list(x= list(at=seq(5, 15, 1)), y = list(at=seq(0, 10, 1))),
       auto.key =list(
         draw.key=list(text=list("Equipe 1", "Equipe 1'")),
         points = TRUE, 
         columns=2),
       xlab="Température",
       ylab="Profondeur",
)

The result : http://environnementaliste.files.wordpress.com/2013/11/cromwell_temp.jpeg

Somebody have any idea to limit my legend at the relevant information?

Thanks!

Lucas

user2784578
  • 21
  • 1
  • 5
  • Making your example [reproducible](http://stackoverflow.com/q/5963269) will help you get a good answer. – BenBarnes Nov 14 '13 at 15:51

1 Answers1

0

To limit your legend, limit the data that you pass to xyplot. In your code, you rely on the subset argument and pass the entire dataset physico, including the extra factors that you don't want to plot and don't want in the legend. So instead of

...,
data = physico,
subset=lake=="Crom",
...

subset the data that you pass to xyplot and drop the unused levels

...,
data = droplevels(subset(physico, subset = lake == "Crom")),
...

Using reproducible code and the CO2 dataset from the datasets package:

levels(CO2$Plant)
#  [1] "Qn1" "Qn2" "Qn3" "Qc1" "Qc3" "Qc2" "Mn3" "Mn2" "Mn1" "Mc2" "Mc3" "Mc1"

library(lattice)

xyplot(conc~uptake | Type * Treatment,
       type=c("p", "l"),
       data = droplevels(subset(CO2, subset=Type=="Quebec")),
       group=Plant,
       auto.key =list(
         draw.key=list(text=list("Equipe 1", "Equipe 1'")),
         points = TRUE, 
         columns=2),
       xlab="Température",
       ylab="Profondeur",
)

plot with extra levels removed

BenBarnes
  • 19,114
  • 6
  • 56
  • 74
  • Great, thank you! I've hade the same idea, and I've splited my tab, but it's simpler in your way. Problem solved! – user2784578 Nov 16 '13 at 18:20