Skip to content
Back to formatted view

Raw Message

Message-ID: <42F32D90.1030803@cirad.fr>
Date: 2005-08-05T09:12:48Z
From: Renaud Lancelot
Subject: using "for" loop
In-Reply-To: <20050805085808.87956.qmail@web26606.mail.ukl.yahoo.com>

alessandro carletti a ??crit :
> Hi everybody,
> how can I create a loop for plotting parameters for
> each level of a variable, for example:
> 
> NAME   temperature  depth
> aaa      23           -1
> aaa      22           -2
> aaa      24           -1
> bbb      23           -4
> bbb      23           -1 
> aaa      22           -1
> bbb      22            0
> 
> I mean, I would like R to plot temperature vs depth
> for aaa, then another plot for bbb, and so on.
> 
> Is it for loop ok?
> Thanks

Package lattice is your friend. Using your example:

Data <- read.table(file = "clipboard", header = TRUE)
library(lattice)
xyplot(temperature ~ depth | NAME, data = Data)

Best,

Renaud

-- 
Dr Renaud Lancelot, v??t??rinaire
Projet FSP r??gional ??pid??miologie v??t??rinaire
C/0 Ambassade de France - SCAC
BP 834 Antananarivo 101 - Madagascar

e-mail: renaud.lancelot at cirad.fr
tel.:   +261 32 40 165 53 (cell)
         +261 20 22 665 36 ext. 225 (work)
         +261 20 22 494 37 (home)