[R] Plotting lines with equidistant points for identification

Jim Lemon jim at bitwrit.com.au
Tue Apr 19 10:31:45 CEST 2011


On 04/19/2011 06:05 PM, Timo Schneider wrote:
> Dear R Gurus,
>
> I would like to make a line-plot of a large data-set (>200 data-points)
> for a document which will be printed in black and white. The plot will
> contain 5 different lines. So i need a way to differentiate between the
> lines. Since color is not an option i tried different line styles with
> all sorts of "line-gap" or "dot dot dot" patterns. Since my plots are
> rather small it is hard to get lines that look contiguous enough while
> still being identifiable through their line style.
>
> What I would like to have are lines that have symbols on top of them,
> similar to what i get with plot(x,y,type='o'). The problem is that i
> have to many data-points for that method, the symbols will just "melt
> together", as in plot(seq(1,500), seq(1,500), type='o') - just one big
> line.
>
> What i want is to have a configurable number of symbols spread
> equidistantly over the whole graph, regardless of the number or position
> of data-points.
>
> Does anyone have an idea how to achieve this?
>
Hi Timo,
I don't have time to program this at the moment, but the method isn't 
too hard, assuming that your line is defined by a series of x and y 
coordinates.

Define a function, e.g. equiPoints

Pass the x and y coordinate vectors and the distance between symbols

Start at the leftmost end of the line, recording the x/y coordinates

Calculate the length of successive segments until the cumulative length 
is >= the desired distance

Interpolate the x and y coordinates of the last segment to get the next 
position for a symbol

Add these x and y coordinates to the x and y coordinate vectors

Repeat until you reach the end of the line

Use the symbols function to plot the symbols at the coordinates you have 
calculated

Jim



More information about the R-help mailing list