[R] Stacked area chart and legends

hadley wickham h.wickham at gmail.com
Mon Oct 6 19:55:09 CEST 2008

On Mon, Oct 6, 2008 at 10:54 AM, mbr <mattblakley at gmail.com> wrote:
> I have found lots of good advice on this forum about stacked area charts but
> I've run into problems with the 2 recommended options: stackploy in plotrix
> or qplot in ggplot2. I have a many page report that will be in a 2x2 page
> format "par(mfrow=c(2,2))"" and need one of the page components to be a
> stacked chart.
> I'd prefer to use stackpoly, if possible, but I'm stuck on how to do the
> legend in hopefully a relatively simple way. I just need a simple legend to
> be outside the plot area (b/c the plot area is full as I'm doing it as 100%
> stacked area chart format) on the right side with the little box with the
> color and the series name next to it – same/similar to Excel format.
> The qplot approach would work as well and seems like the legend is built
> into the default, but the graph always ends up on its own page and can't
> figure out how to force it into one of boxes of my 2x2 page layout. I like
> the looks of the stackpoly more as consistent with other graphs I have on
> report but qplot stacked chart would be fine if I could get it into the
> layout.

http://had.co.nz/ggplot2/book/grid.pdf describes how to position
multiple ggplots on the same page.  However, this won't work with a
mix of base graphics and grid graphics (like lattice or ggplot).  You
either need to create all of your plot with one plotting system, or
jump through some slightly painful hoops.



More information about the R-help mailing list