[R] A question on type="h" plot lines

Jim Lemon jim at bitwrit.com.au
Mon May 25 10:50:11 CEST 2009


Martin Ivanov wrote:
> Dear R users,
> I need a produce a plot with a single panel and a few lines on it. Each line represents a different data set. The line types must be "h", i.e. ‘histogram’ like (or ‘high-density’) vertical lines. The problem is that the vertical lines comprising a plot line of type="h" are drawn from the y=0 line to the (x, y) locations. What I need is vertical lines drawn from the line y="value that I specify" to the (x, y) locations. Is there a way for me to achieve that?
>
>   
Hi Martin,
If you want a constant "value that you specify", you can just use the 
"clip" function:

plot(x,y,type="n",...)
xylim<-par("usr")
clip(xylim[1],xylim[2],"value that I specify",xylim[4])
points(x,y,type="h")

If you want different "values that you specify", I defer to the other Jim.

Jim




More information about the R-help mailing list