[R] Basic graphs: something like groups, but where each plot has independent axis?

Sharpie chuck at sharpsteen.net
Thu Mar 25 17:26:41 CET 2010



Ben Bimber wrote:
> 
> I am trying to graph weight data for our colony.  We a data frame with
> Animal, Weight and Date.  I'd like to display this data a series of simple
> xyplots.  We only need to display these plots together, we do not need to
> make comparisons between animals.  Each animal has been weighted over a
> different time period, so we do not want the same range for each X axis.
> 
> 
> Using the following, I can create one plot per animal:
> 
> size <- length(unique(data$id))
> xyplot(weight ~ date | id,
>     data=data,
>     #type="o",
>     layout=c(1,size),
>     xlab="Date",
>     ylab="Weight"
>     );
> 
> However, they share a common X axis.  Is it possible to avoid this?  In
> other words, I might want the first animal's plot to extend from
> 2008-01-01
> through 2009-05-04, while the second plot extends from 2007-02-04 through
> 2010-01-01.
> 
> Also, can I introduce more whitespace between each plot?
> 
> Thank you for any help.
> 

You can do this in ggplot2 using facet_wrap( ~ id, scales = "free_x" ):

  colonyPlot <- qplot( date, weight, data = data,
    xlab = "Date",
    ylab = "Weight" ) +
    facet_wrap( ~ id, scales = "free_x" ) +
    theme_bw()

  print( colonyPlot )


Not sure about hot to do it using xyplot though.  The following website may
help for ggplot2:

  http://had.co.nz/ggplot2/facet_wrap.html


Good luck!

-Charlie

-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://n4.nabble.com/Basic-graphs-something-like-groups-but-where-each-plot-has-independent-axis-tp1690870p1690937.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list