Dear useRs,
I have a data frame and I want to plot all rows. Each row is
represented as a line that links the values in each column. The plot
looks like this:
dfr <- data.frame(A=sample(1:50,10),B=sample(1:50,10),
C=sample(1:50,10),D=sample(1:50,10))
xa <- 10*1:4
plot(c(10,40),c(0,50))
for (i in 1:nrow(dfr)) {
lines(xa,dfr[i,],pch=20,type="o")
}
Things get more complicated because I want the columns to be rescaled
so as to fit nicely on a graph (for example if A has values between 0
and 100 but B has values between 100 and 1000, then rescale A or B),
labels etc. Is there a function that can do plots like this?
Thank you,
b.
If your data were in the long format you could use interaction.plot.
But, I think trellis plots in lattice are much better than this
approach.
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of bogdan romocea
Sent: Wednesday, April 06, 2005 4:19 PM
To: r-help at stat.math.ethz.ch
Subject: [R] looking for a plot function
Dear useRs,
I have a data frame and I want to plot all rows. Each row is represented
as a line that links the values in each column. The plot looks like
this:
dfr <- data.frame(A=sample(1:50,10),B=sample(1:50,10),
C=sample(1:50,10),D=sample(1:50,10))
xa <- 10*1:4
plot(c(10,40),c(0,50))
for (i in 1:nrow(dfr)) {
lines(xa,dfr[i,],pch=20,type="o")
}
Things get more complicated because I want the columns to be rescaled so
as to fit nicely on a graph (for example if A has values between 0 and
100 but B has values between 100 and 1000, then rescale A or B), labels
etc. Is there a function that can do plots like this?
Thank you,
b.
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
On Wednesday 06 April 2005 15:18, bogdan romocea wrote:> Dear useRs, > > I have a data frame and I want to plot all rows. Each row is > represented as a line that links the values in each column. The plot > looks like this: > > dfr <- data.frame(A=sample(1:50,10),B=sample(1:50,10), > C=sample(1:50,10),D=sample(1:50,10)) > xa <- 10*1:4 > plot(c(10,40),c(0,50)) > for (i in 1:nrow(dfr)) { > lines(xa,dfr[i,],pch=20,type="o") > } > > Things get more complicated because I want the columns to be rescaled > so as to fit nicely on a graph (for example if A has values between 0 > and 100 but B has values between 100 and 1000, then rescale A or B), > labels etc. Is there a function that can do plots like this?Not sure if it fits all your needs, but try 'parallel' in the lattice package. Deepayan
I am not sure about the scaling, but doing simply
matplot(xa, t(dfr), type="b")
does most of what you want.
Andy
__________________________________
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-----
E-mail: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
"Doran, Harold"
<HDoran at air.org>
Sent by: To
r-help-bounces at st "bogdan romocea"
at.math.ethz.ch <br44114 at yahoo.com>,
<r-help at stat.math.ethz.ch>
cc
04/06/2005 03:24
PM Subject
RE: [R] looking for a plot function
If your data were in the long format you could use interaction.plot.
But, I think trellis plots in lattice are much better than this
approach.
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of bogdan romocea
Sent: Wednesday, April 06, 2005 4:19 PM
To: r-help at stat.math.ethz.ch
Subject: [R] looking for a plot function
Dear useRs,
I have a data frame and I want to plot all rows. Each row is represented
as a line that links the values in each column. The plot looks like
this:
dfr <- data.frame(A=sample(1:50,10),B=sample(1:50,10),
C=sample(1:50,10),D=sample(1:50,10))
xa <- 10*1:4
plot(c(10,40),c(0,50))
for (i in 1:nrow(dfr)) {
lines(xa,dfr[i,],pch=20,type="o")
}
Things get more complicated because I want the columns to be rescaled so
as to fit nicely on a graph (for example if A has values between 0 and
100 but B has values between 100 and 1000, then rescale A or B), labels
etc. Is there a function that can do plots like this?
Thank you,
b.
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html