[R] overlaid transparent histograms

hadley wickham h.wickham at gmail.com
Sat Jun 14 06:45:44 CEST 2008


> Three questions:
> 1a)  Why does the following code not produce transparent bars?

Because you're setting the fill colour (not mapping it to a variable
in your dataset), the fill needs to be outside of aes()

g +
 geom_histogram(aes(x=log(BNCw)), fill = alpha("red", .5)) +
 geom_histogram(aes(x=log(BNCc)), fill = alpha("blue", .5))


> 1b)  How can I manually specify the elements of the legend for this
>     version of the plot?

Use the "manual" scale:

g +
geom_histogram(aes(x=log(BNCw), fill = "w")) +
geom_histogram(aes(x=log(BNCc), fill = "c")) +
scale_fill_manual("BNC type", values = alpha(c("red","blue"), 0.5))

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list