[R] Plotting a broken line?
Aldi Kraja
aldi at wustl.edu
Wed Mar 7 17:21:06 CET 2007
Hi,
Is there a smart way in the R graphs to create a line that is broken in
intervals based on the indicator given below.
following is a small test graph
Location,indicator,otherinfo
1.2,1,2.2
2.5,1,2.5
3.7,1,2.3
20.1,2,4.3
22.5,2,5.2
25.0,2,3.4
27.3,2,2.2
35.1,3,3.4
37.0,3,7.2
38.0,3,6.1
40.1,3,5.4
52.9,3,3.3
Right now in the plot the line is continuous, but I would like to have
it broken based on the indicator. If the line of the plot reaches the
last observation of indicator=1 then the line needs to stop; the next
line will start at location 22.5 and continue up top 27.3; the next line
goes from 35.1 up to 52.9.
> x<-read.table(file='c:\\aldi\\testgraph.csv',sep=',',header=T)
> x
Location indicator otherinfo
1 1.2 1 2.2
2 2.5 1 2.5
3 3.7 1 2.3
4 20.1 2 4.3
5 22.5 2 5.2
6 25.0 2 3.4
7 27.3 2 2.2
8 35.1 3 3.4
9 37.0 3 7.2
10 38.0 3 6.1
11 40.1 3 5.4
12 52.9 3 3.3
>
plot(x$Location,x$indicator,type='l',xlim=c(0,max(x$Location)),ylim=c(0,max(x$indicator,x$otherinfo)))
> points(x$Location,x$otherinfo)
TIA,
Aldi
--
More information about the R-help
mailing list