Jordan Ouellette-Plante
2010-Aug-25 13:16 UTC
[R] multiple x factors using the sciplot package
Dear R community, I am a beginner using the sciplot package to graph barplots. I would like to be able to graph two x factors (Sampling.year and Period). Sampling.year: 2006, 2007, 2008, 2009 Period: First, Second, Total The parameter "group" is the different species I looked at. They can be seen in the legend. The parameter "response" is the Average percentage cover category of these species. I would like the graph so you see on the x axis the years (in a bigger font) and the period (in smaller font). It would look a bit like the barplot that can be seen at http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html, but with the advantage of the sciplot package. Thanks a lot for your help! Jordan [[alternative HTML version deleted]]
Hi: You can probably do what you want in either ggplot2 or lattice, but I would recommend at least a couple different approaches: (1) Plot individual bar charts by combinations of year and period. This is easy to do in both ggplot2 and lattice: in ggplot2, one would use geom_bar(x) + facet_grid(year ~ period), where x is the count variable. The same thing in lattice would be barchart( ~ x | year * period, data = mydata). Suitable options can be added to either plot for better presentation. All the plots are on the same horizontal and vertical scales so that visual comparisons across the rows and columns are easy to make. (2) Use a Cleveland dot chart. This is much less wasteful of ink than bar charts, and multiple groups can be compared without too much difficulty. See dotplot() in lattice for details. The VADeaths example is likely the best one to emulate for your problem. Both the input data structure and plot code matter. (3) If your purpose is to compare the two groups with respect to a count variable, a third option is to consider a mosaic plot, which can be thought of as a 'visual chi-square test'. These can be found in package vcd, which contains a nice 40+ page vignette to show you in detail how to create a suitable mosaic plot (and how to interpret it). I prefer to see R used to promote good graphics and sound statistical principles. In that spirit, performing a two-factor comparison with count data is easier, and quite possibly more instructive, with a 2D visual metaphor (which all three of the suggestions above have in common) than with the 1D metaphor of multiple dodged/side-by-side bar charts. Of course, this may be against the standard practice in your field, in which case you have a decision to make. HTH, Dennis On Wed, Aug 25, 2010 at 6:16 AM, Jordan Ouellette-Plante < jordan_oplante@hotmail.com> wrote:> > Dear R community, > > > > I am a beginner using the sciplot package to graph barplots. I would like > to be able to graph two x factors (Sampling.year and Period). > > Sampling.year: 2006, 2007, 2008, 2009 > > Period: First, Second, Total > > > > The parameter "group" is the different species I looked at. They can be > seen in the legend. > > The parameter "response" is the Average percentage cover category of these > species. > > > > I would like the graph so you see on the x axis the years (in a bigger > font) and the period (in smaller font). It would look a bit like the barplot > that can be seen at > http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html, > but with the advantage of the sciplot package. > > > > > > Thanks a lot for your help! > > > > Jordan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Apparently Analagous Threads
- Problem with bargraph.CI in Sciplot package
- error in bargraph.CI {sciplot}
- introducing jitter in overlapping graphs using ggplots (plotmeans). Also sciplot.
- How to plot 2 continous variables on double y-axis with 2 factors: ggplot2, gplot, lattice, sciplot?
- lineplot.CI in "sciplot": option "ci.fun" can't be changed?