[R] overlaid transparent histograms

From: Austin Frank <austin.frank_at_gmail.com>
Date: Fri, 13 Jun 2008 19:06:05 -0400


Hello all--

I'm attempting to produce overlaid histograms with partially transparent columns. Whether this display will end up being useful, I can't say. But I do want to get it right.

I've already got one solution (shown below), but I tried some other versions and had questions about my results. (Note: I'm using a quartz device, so transparency shows up correctly. You might need to print to a pdf device to get transparency, according to the docs I've read)

--8<---------------cut here---------------start------------->8--- ## Working version:
data(lexdec, package="languageR")
attach(lexdec)

x <- log(c(BNCw, Frequency))

label <-  c(rep("BNCw", length(BNCw)),
            rep("CELEX", length(Frequency)))
h <- data.frame(x, label)

g <- ggplot(h, aes(x=x, fill=label))
g +
  geom_bar(position="identity") +
  scale_fill_manual(values = c(

                      alpha("red", 0.5),
                      alpha("blue", 0.5)))
detach(lexdec)                      

--8<---------------cut here---------------end--------------->8---

Three questions:
1a) Why does the following code not produce transparent bars? 1b) How can I manually specify the elements of the legend for this

     version of the plot?

--8<---------------cut here---------------start------------->8--- ## Non-working version
data(lexdec, package="languageR")

g <- ggplot(lexdec)
g +
  geom_histogram(aes(x=log(BNCw), fill = alpha("red", .5))) +   geom_histogram(aes(x=log(BNCc), fill = alpha("blue", .5))) --8<---------------cut here---------------end--------------->8---

2) Does anyone have a way to accomplish the same thing in lattice? I

   saw the post at
   http://www.nabble.com/Overlay-plots-from-different-data-sets-using-the-Lattice-package-tp14824421p14824421.html,    but couldn't figure out how to extend these suggestions to overlaid    transparent histograms.

Thanks in advance for any help,
/au

> sessionInfo()

R version 2.7.0 (2008-04-22)
powerpc-apple-darwin8.10.1

locale:
C

attached base packages:

[1] grid      splines   stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] ggplot2_0.6        colorspace_0.95    RColorBrewer_1.0-2 MASS_7.2-42       
 [5] proto_0.3-8        reshape_0.8.0      languageR_0.92     coda_0.13-2       
 [9] lme4_0.999375-15   Matrix_0.999375-10 zipfR_0.6-0        lattice_0.17-8    
[13] Design_2.1-1       survival_2.34-1    Hmisc_3.4-3

-- 
Austin Frank
http://aufrank.net
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc

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

  • application/pgp-signature attachment: stored
Received on Sat 14 Jun 2008 - 02:45:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 Jun 2008 - 05:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive