[R] ggplot2 - ribbon

Brian Diggs diggsb at ohsu.edu
Mon Jan 24 21:49:45 CET 2011

On 1/24/2011 7:44 AM, Sam wrote:
> Dear List,
> I am having trouble setting the transparency of a ribbon in ggplot2
> and was wondering if anybody had any suggestions
> so far i have a plot exactly as i want it and i want to add a ribbon
> connecting the ymax and ymin, whci i do with the following command
> m10 + stat_summary(geom="ribbon", fun.ymin="min", fun.ymax="max")
> However the ribbon is a dark grey and i want to make it much lighter
> or change the colour. I was wondering if anybody had any ideas?
> I have kept the code used so far brief as it is quite long, however i
> can expand if required.

To see what is happening, a simple toy example works; the details of 
your specific graph aren't needed.

p <- ggplot(mtcars, aes(x=carb, y=mpg)) + geom_point()

p + stat_summary(geom="ribbon", fun.ymin="min", fun.ymax="max")

p + stat_summary(geom="ribbon", fun.ymin="min", fun.ymax="max",
	alpha=0.2, fill="blue")

You can set the transparency (alpha) of the fill and the color of the 
fill (fill) to whatever you want.  You can also set the color of the 
lines around the fill with colour. As fixed (not data determined) 
values, they are not inside an aes call.

> Thanks
> Sam

Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

More information about the R-help mailing list