[R] Re: Bar plot with variable width (down a drill hole) - n
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Wed Mar 26 10:59:23 CET 2003
On 25-Mar-03 Phillip J. Allen wrote:
> Thanks Ted and Marc its works. But of course after pulling in in some
> real life data I discoverd one hitch. Often there are missing
> intervals. For example:
> from <- c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
> to <- c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
> intensity <- c(0, 1, 3, 2, 1, 0, 2, 5)
> barplot(intensity, width = -(to - from),
> space = 0, horiz = TRUE, ylim = c(-40, 0))
>
> And it appears a barplot() is just stacking bars one on top the other
> and the help page doesn't indicate anyway to position the bar along the
> y-axis. So does anyone have a nifty trick to to fill in blank gaps?
> At least my database can check for "overlaping" intervals before I
> get the data into R.
Well, I have constructed "by hand" for the above example a way of
doing it. First, I have used the "add a small bit to true zeros"
trick to make these stand out from the line of the axis; secondly,
I have filled in the gap where there are no data by inserting
the width of the gap into "width" (which I call "w"), and inserting
a true zero into "intensity" (which I call "y"). This one-off code
is as follows (starting with your 3 lines which define the data):
from <- c(0, 1.2, 4.0, 4.2, 5.0, 25.0, 30.1, 45)
to <- c(1.2, 4.0, 4.2, 5.0, 25, 30.1, 36.2, 50)
intensity <- c(0, 1, 3, 2, 1, 0, 2, 5)
y<-intensity;
y[y==0]<-0.005;
y<-c(y[1:7],0,y[8])
w<-(-(to - from))
w<-c(w[1:7],-(45-36.2),w[8])
barplot(y, w, space = 0, horiz = TRUE, ylim = c(-50, 0))
This does produce a plot which represents the full situation:
positive intensities get a proper "bar"; gaps with missing
data are represented by the line of the vertical axis;
intervals with intensity=0 are represented by a thickened
segment of the vertical axis.
However, this kind of situation needs thought about alternative
ways of representing it.
One possibility might be to have the vertical axis invisible,
so that gaps in the data are represented by gaps in the axis
(and then there would be no need for "adding a bit to true zeros").
Possibly this can be arranged by some setting of "par", though
I can't seem to achieve it with barplot. Ideas, anyone?
(It looks as though "axis" in barplot means the scale which is
plotted below or on the side, and not the lines which bound the
barplot itself).
Other thoughts are based on how I might approach this plotting
problem outside R. In particular, I might draw this kind of
graph using the 'pic' program in troff (groff for GNU people).
With this, it would be straightforward to draw the vertical
axis dotted, or dashed, or blank, wherever there is an interval
with missing data; otherwise, as an unbroken line.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 26-Mar-03 Time: 09:59:23
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list