mbr 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.

Hi Matt,
The easy way is to make your device wider than it is high:

# use the screen device for the example
x11(width=10,height=7)
#leave lots of room on the right side of the plot:
par(mar=c(5,4,4,10))
#then plot, stop clipping to the plot region, add the legend
# and restore clipping
stackpoly(matrix(abs(rnorm(30)),nrow=10),stack=TRUE,
main="Look ma. just like Excel!")
par(xpd=TRUE)
legend(11,3,1:5,fill=1:5)
par(xpd=FALSE)

Jim

______________________________________________
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.

Reply via email to