[R] ReShape chicks example - line plots

Mark Knecht markknecht at gmail.com
Mon Jul 6 20:22:18 CEST 2009


Hi,
   In the examples from the ReShape package there is a simple example
of using melt followed by cast that produces a smallish amount of
output about the chicks database. Here's the code:

library(reshape)

names(ChickWeight) <- tolower(names(ChickWeight))
chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE)
DietResults <- cast(chick_m, diet + chick ~ time)
DietResults

   My challenge is to extract an plot only a portion of this data.

   I would like to plot the data for each chick that participated in
diet 1 only. Assume that the numbered column names (0,2,4, ...)
represent time on the diet and will be the X axis. Y values on the
plot will be the value in the table. (chick weight) Y maximum should
be larger than the max value in the diet 1 portion of the table.
Additionally if a chick's number is even I would like to plot it's
results in green, if it's odd then plot in red. The plot should use a
line type so that in the general case I could trace an individual
chick's progress on the diet. I don't care if I use plot vs any other
command that would make a plot with colored lines. I would *prefer*
that the code discovers where in DietResults the column entitled "0"
is as I don't know where the beginning of the data will be based on
how many variables I bin for in cast.

   Hopefully this is relatively straight forward to do. If it isn't
then maybe I can understand why and do something better with cast to
make it easy. My real data set is much larger and has a lot of
different bins for both selection, colorizing and line type but after
using ReShape it looks similar to this one so this plot would be
helpful to me.

Thanks,
Mark




More information about the R-help mailing list