[R] Loop FOR with histogram() from lattice

Xochitl CORMON Xochitl.Cormon at ifremer.fr
Wed Jun 5 10:37:16 CEST 2013

Hi all,

I'm encountering a problem I do not understand on my data:

library (lattice)

Mpool1 <- Table[Table$Subarea %in% c("52E9", "51E9"),]
Mpool2 <- Table[Table$Subarea %in% c("53F0", "52F0"),]
Mpool3 <- Table[Table$Subarea %in% c("51F0", "50F0"),]
Mpool4 <- Table[Table$Subarea %in% c("51F1", "52F1"),]

Mpool <- list(Mpool1, Mpool2, Mpool3, Mpool4)

histogram(~ Mpool[[2]]$LngtClas | Mpool[[2]]$SpCode, type = "count", col 
= "lightgrey", xlab= "LngtClas", main = paste("Length distribution per 
species for Mpool", "2", sep = "_"))

#### This part works perfectly and I obtain the graph reprensenting 
Mpool2 length class count per species.
#### Now when I want to automatize this with a "for" loop nothing is 

for (i in c(2)){
histogram(~ Mpool[[i]]$LngtClas | Mpool[[i]]$SpCode, type = "count", col 
= "lightgrey", xlab= "LngtClas", main = paste("Length distribution per 
species for Mpool", i, sep = "_"))
print (i)

### Running this loop I obtained  windows filled grey (no plot drawn at 
all) but the print (i) print a "2" as expected. I really dont understand 
what's wrong with the loop. There is no error message and no 
notification in R. You can find enclosed my data in txt file.

Thank you very much for any help,

Xochitl C.

<>< <>< <>< <><

Xochitl CORMON
+33 (0)3 21 99 56 84

Doctorante en sciences halieutiques
PhD student in fishery sciences

<>< <>< <>< <><

Centre Manche Mer du Nord
150 quai Gambetta
62200 Boulogne-sur-Mer

<>< <>< <>< <><

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Table.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130605/4df6b793/attachment.txt>

More information about the R-help mailing list