[R] Plot Stepped Line chart with multiple lines
Techni X
fibosworld at yahoo.com
Wed Feb 23 08:21:25 CET 2011
Hi Ista, David,
your answers indeed helped me to solve the problem!
So thanks to you and have a good day!
Stephan
--- On Wed, 2/23/11, David Winsemius <dwinsemius at comcast.net> wrote:
> From: David Winsemius <dwinsemius at comcast.net>
> Subject: Re: [R] Plot Stepped Line chart with multiple lines
> To: "Ista Zahn" <izahn at psych.rochester.edu>
> Cc: "Techni X" <fibosworld at yahoo.com>, r-help at r-project.org
> Date: Wednesday, February 23, 2011, 2:08 AM
>
> On Feb 22, 2011, at 7:10 PM, Ista Zahn wrote:
>
> > Hi,
> > This is R, so there are bound to be severay ways to do
> it. This would
> > be my first choice:
> >
> > library(ggplot2)
> > ggplot(d, aes(x=V2, y=V3, color=V1)) + geom_step()
> >
> > Best,
> > Ista
> >
> > On Tue, Feb 22, 2011 at 3:08 PM, Techni X <fibosworld at yahoo.com>
> wrote:
> >> Hi all,
> >>
> >> I have a question, that might be a „rookie“
> question – but I’m trying now for days and cannot get my
> head around. The general question is:
> >> How can I plot a stepped line chart with multiple
> lines from a subset of a dataframe?
> >>
> >> An example:
> >> d <- matrix(rep(0,24), ncol=3, nrow=8)
> >> d <- as.data.frame(d)
> >> d$V1 <- c("A","A","A","B","B","C","C","C")
> >> d$V2 <- c(5,10,15,10,15,5,13,15)
> >> d$V3 <- c(10,20,30,7.5,10,3,7,10)
>
> Probably the second to these:
>
> require(lattice)
> xyplot(V3 ~ V2|V1, data=d, type="s") #separate
> panels
> xyplot(V3 ~ V2, group=V1, data=d, type="s") # all on
> one panel
>
> >> which gives me the following dataframe:
> >> V1 V2 V3
> >> 1 A 5 10.0
> >> 2 A 10 20.0
> >> 3 A 15 30.0
> >> 4 B 10 7.5
> >> 5 B 15 10.0
> >> 6 C 5 3.0
> >> 7 C 13 7.0
> >> 8 C 15 10.0
> >>
> >> I now want to plot three stepped lines into a x-y
> chart, the lines representing A, B, C. The x-axis is given
> by V2, the y-axis by V3, thus each line will be
> “ascending”
> >> It must be something with SUBSET or so, but I do
> not find an easy way.
> >>
> >> Can anybody help me?
> >>
> >> Thanks
> >> Stephan
>
>
> David Winsemius, MD
> West Hartford, CT
>
>
More information about the R-help
mailing list