Fits kernel density functions to two data sets and plots them, shading the area corresponding to the coefficient of overlap.

1 2 3 4 |

`A, B` |
vectors of times of observations for species A and species B in |

`xscale` |
the scale for the x axis: 24 (the default) produces a curve with 0 to 24 hours. NA gives a scale in radians, labelled with |

`xcenter` |
the center of the plot on the x axis: 'noon' (default) or 'midnight'. |

`linetype` |
a vector of length 2 giving the line type for each species. Look for |

`linecol` |
a vector of length 2 giving the line colour for each species. See the Color Specification section in |

`linewidth` |
a vector of length 2 giving the line width for each species. |

`olapcol` |
the colour to use for the shaded area. See the Color Specification section in |

`rug` |
if TRUE, the original observations will be displayed as a rug at the bottom of the plot, A below B. |

`extend` |
If not NULL, the plot extends 3 hours before and after the main 24-hr period, and |

`n.grid` |
number of points at which to estimate the density for plotting; 100 is usually adequate to give a smooth-looking curve. |

`kmax` |
maximum value of k for optimal bandwidth estimation. |

`adjust` |
bandwidth adjustment (scalar). |

`...` |
Further arguments passed to the plotting functions such as |

Returns invisibly a data frame with columns:

`x` |
a vector of equally-spaced times from midnight to midnight inclusive on the scale specified by |

`densA` |
a vector of length |

`densB` |
a similar vector for species B. |

Mike Meredith

`densityPlot`

for plotting a single density curve.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ```
# Get example data:
data(simulatedData)
# Do basic plot with defaults:
overlapPlot(pigObs, tigerObs)
# Make it prettier:
overlapPlot(tigerObs, pigObs, linet = c(1,1), linec = c("red", "blue"),
rug=TRUE, extend="lightgreen", main="Simulated data")
legend("topleft", c("Tiger", "Pig"), lty=1, col=c("red", "blue"), bg="white")
# Add vertical dotted lines to mark sunrise (05:30) and sunset (18:47):
# (times must be in hours if the x-axis is labelled in hours)
abline(v=c(5.5, 18+47/60), lty=3)
# A plot centered on midnight:
overlapPlot(pigObs, tigerObs, xcenter = "m", rug=TRUE)
# Mark sunrise/sunset; values to the left of "00:00" are negative
# so subtract 24:
abline(v=c(5.5, (18+47/60) - 24), lty=3)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.