[R] difference between two density plots

Duncan Murdoch murdoch at stats.uwo.ca
Thu Apr 6 20:01:07 CEST 2006


On 4/6/2006 1:34 PM, Philipp H. Mohr wrote:
> Hello,
> 
> I have two densities which I plot with:
> 
> sm.density(gps)
> sm.density(gps2)
> 
> Both data sets are 2D and have the same scale.
> 
> Is there a way of plotting the difference between the two density plots ?

?sm.density describes the value returned by those function calls, which 
includes "the values of the density estimate at the evaluation points". 
   The evaluation points may be different between the two datasets, but 
you could use approxfun to generate functions doing linear interpolation 
for each of them, and then evaluate the density difference whereever you 
like.

Duncan Murdoch




More information about the R-help mailing list