[R] Loop FOR with histogram() from lattice
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Wed Jun 5 10:52:42 CEST 2013
Hi, Xochitl,
wrapping the call to histogram() inside your loop in a call to print()
should solve your problem:
print( histogram( .....))
Regards -- Gerrit
On Wed, 5 Jun 2013, Xochitl CORMON wrote:
> 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 plotted.
>
> for (i in c(2)){
> windows()
> 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
>
> <>< <>< <>< <><
>
> IFREMER
> Centre Manche Mer du Nord
> 150 quai Gambetta
> 62200 Boulogne-sur-Mer
>
> <>< <>< <>< <><
>
More information about the R-help
mailing list