[R] ggplot question

hadley wickham h.wickham at gmail.com
Thu Jul 24 17:43:29 CEST 2008

On Thu, Jul 24, 2008 at 2:23 AM, Williams Scott
<Scott.Williams at petermac.org> wrote:
> I am trying to do something simple with ggplot. I wish to draw a density
> plot split by group, and fill each group with a different colour (and
> each with an alpha =0.25). I have tried a number of variations of the
> following, but cannot find a way to define the colour of the fill, its
> transparency and the line around it individually - something in the
> syntax continues to defy me.

To fill each density with a different colour you want:

 + geom_density(aes(fill=group))

I'm not sure what you want to do with the line, but I'm going to guess
you want to make it transparent:

 + geom_density(aes(fill=group), colour = NA)

The slightly tricky thing is then making these colours transparent -
it's the scale that's responsible for converting data values into
shades of colour, so you'll need to change options there:

 + scale_fill_hue(alpha = 0.25)

Does that help?



More information about the R-help mailing list