[R] Overlaying data on graphs

Steven Murdoch r+Steven.Murdoch at cl.cam.ac.uk
Tue Oct 19 11:18:59 CEST 2004


[sorry, my last message seems to have been corrupted - here it is
again.]

I currently have a graph from network measurements of latency against
time and would like to overlay some extra data on top, but with a
different y scale, but I am not sure how to do this in an automated
manner.

The base graph is generated by these commands:
 time=probe$rsec+(probe$rusec/1000000)
 diff=((probe$rsec-probe$ssec)*1000000)+(probe$rusec-probe$susec)
 plot(time[100:len],diff[100:len])

Then I would like to overlay data on the usage of the network. In this
data the x scale is the same (time), but the y axis is unrelated
(buffer size). The approach I have currently been using is simply
drawing on top of the graph:
 lines(usage$time,(usage$bytes)*m+c,type="h",col="blue")

The problem with this is that to make the lines visible, but not
taking up the whole height, I need to manually tweak the m and c
factors, based on the relative values of the usage and probe data.
Since I have a lot of graphs to generate, I would like to do this
automatically.

I haven't been able to do this, because I can't find out the ymin and
ymax of the graph generated by plot. If I could then it would be
trivial to scale the factors so they took up say, 10% of the vertical
space. There is par("yaxp"), but this shows the positions of the
tickmarks, but these can be different from the actual ymin and ymax.
Is there a way to do this?

The alternative would be to have two graphs, one on top of the other.
With the latency graph on top, taking up most of the space, and the
usage graph below, with the scale of the n axis being identical.
However I can't see how do this.

Does anyone have any advice?

Thanks in advance,
Steven Murdoch.




More information about the R-help mailing list