[R] Plot Stepped Line chart with multiple lines

Techni X fibosworld at yahoo.com
Tue Feb 22 21:08:25 CET 2011


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



 


More information about the R-help mailing list