Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a little function to plot overlapping histograms with pseudo-transparency:</p> <p><a href="http://chrisamiller.com/images/histOverlap.png">Overlapping Histograms http://chrisamiller.com/images/histOverlap.png</a></p> <pre><code>plotOverlappingHist &lt;- function(a, b, colors=c("white","gray20","gray50"), breaks=NULL, xlim=NULL, ylim=NULL){ ahist=NULL bhist=NULL if(!(is.null(breaks))){ ahist=hist(a,breaks=breaks,plot=F) bhist=hist(b,breaks=breaks,plot=F) } else { ahist=hist(a,plot=F) bhist=hist(b,plot=F) dist = ahist$breaks[2]-ahist$breaks[1] breaks = seq(min(ahist$breaks,bhist$breaks),max(ahist$breaks,bhist$breaks),dist) ahist=hist(a,breaks=breaks,plot=F) bhist=hist(b,breaks=breaks,plot=F) } if(is.null(xlim)){ xlim = c(min(ahist$breaks,bhist$breaks),max(ahist$breaks,bhist$breaks)) } if(is.null(ylim)){ ylim = c(0,max(ahist$counts,bhist$counts)) } overlap = ahist for(i in 1:length(overlap$counts)){ if(ahist$counts[i] &gt; 0 &amp; bhist$counts[i] &gt; 0){ overlap$counts[i] = min(ahist$counts[i],bhist$counts[i]) } else { overlap$counts[i] = 0 } } plot(ahist, xlim=xlim, ylim=ylim, col=colors[1]) plot(bhist, xlim=xlim, ylim=ylim, col=colors[2], add=T) plot(overlap, xlim=xlim, ylim=ylim, col=colors[3], add=T) } </code></pre> <p>An example of how to run it:</p> <pre><code>a = rnorm(10000,5) b = rnorm(10000,3) plotOverlappingHist(a,b) </code></pre> <hr> <p>Update: FWIW, there's a potentially simpler way to do this with transparency that I've since learned:</p> <pre><code>a=rnorm(1000, 3, 1) b=rnorm(1000, 6, 1) hist(a, xlim=c(0,10), col="red") hist(b, add=T, col=rgb(0, 1, 0, 0.5) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload