[R] Plot Stepped Line chart with multiple lines

Ista Zahn izahn at psych.rochester.edu
Wed Feb 23 01:10:09 CET 2011


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)
> 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
>
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list