Skip to content

plotting multiple data sources

3 messages · myshare, Greg Snow, Penner, Johannes

#
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
#
It is not recommended to plot variables on different scales on the same graph.  You can use something like par(mfrow=...) (see ?par) to stack graphs on top of each other (or next to each other, or both) for easy comparison, but each with their own scales/axes.

If you have considered all that and still feel the need to put the data in the same graph, look at the updateusr function in the TeachingDemos package as a way to convert the scales/axis range from the original (date) version to that matching your new data.

For the labeling of the axis, you can use the axis command and tell it exactly which ticks and labels to use (you can have it do every other label, then do the skipped ones down 1 line with a second call), or you can rotate the labels (often ugly, be careful) or other things.  There are also some tools in the plotrix package that help with long labels (and probably other packages as well).

Hope this helps,
#
Dear R-list,

another question trying to build consensus cluster ;-)

Using the package "clue" I have found a method of building consensus
clusters the following way from one distance matrix:

clust1 <- c("ward", "single", "complete", "average", "mcquitty",
"median", "centroid")
clust_res <- lapply(clust1, function(m) hclust(data2, m))
names(clust_res) <- clust1 
hens <- cl_ensemble(list = clust_res)
plot(hens, main = names(hens))

cons1 <- cl_consensus(hens, method=NULL, weights=1, control=list())

However, now I want to include several distance matrices and build the
ensembles from these. Is this possible and if yes how?

Thank you very much in advance!
Johannes