[R] plotting multiple data sources

myshare mraptor at gmail.com
Thu May 14 01:58:46 CEST 2009


hi,

Excuse me asking three questions in a row for a day, but I had
collected those questions
as I'm still experimenting with R.
This one is how do you compose plots with alot of data in one graph.
First what I currently do is after i generated all the data I need to
plot.. let say 5-6 arrays
I do a plot() and then I created a function to scale the other data to
approx fit the initial range
so it can fit plotted data and then draw it with lines().

Here is the example function I use.

Blah.scale_to_range = function(self,data,range_low=0,range_high,
skip_cond=(data > 0) ) {
  ratio <- (range_high - range_low) / (max(data) - min(data))
  ((data - min(data)) * ratio) + (range_high - range_low)/2
}

so far so good.. the problem I have is that I want the x axis to be Date range.
I can plot( x$date, x$values, type='l'), but then later if I want to
plot the other data with lines()
I can't plot them anymore, cause it seems that the lines() wants the
other data X-axis values to
be dates. I think I was able to draw them referencing the x$date i.e.
something like this :

lines(x$date,scaled_array1)

but isn't there some easier way, especially if it can autoscale the
new data too.
Then my next question is how to change the axis labels so it does show
x-axis label only every
n-th tick.
AFAIR I was able to force it to show date every tick with axis() and
even positioned it vertically,
but all the dates are overlapped..
By default dates are very sparsed, so that is why I want to be able to
control when
the x-labels-dates to show up.


thanx




More information about the R-help mailing list