View source: R/plotFun.kde2d.hist.R
plotFun.kde2d.hist | R Documentation |
Plot a 2-dimensional kernel density plot and the histograms of the two input variables.
plotFun.kde2d.hist(var1, var2, xlim = range(var1, na.rm = T), ylim = range(var2, na.rm = T), breaks.den = NULL, title = NULL, cex.main = 1.5, xlab = NULL, ylab = NULL, n.bins = 25, add.contours = TRUE)
var1 |
vector with data for one variable. |
var2 |
vector with data for another variable. |
xlim |
2-element vector with X-axis limits for the density plot. Default: range of var1. |
ylim |
2-element vector with Y-axis limits for the density plot. Default: range of var2. |
breaks.den |
vector of breaks for the density plots. Example: breaks.den=seq(min, max, length=1000). By default, breaks.den is adjusted to the minimum and maximum kernel densities. |
title |
title above the plot. |
cex.main |
Relative size of the plot title. Default:1.5. |
xlab |
X-axis label. |
ylab |
Y-axis label. |
n.bins |
number of bins for kernel density calculation. Default= 25. |
add.contours |
logical. Add (default) or not contours for the kernel densities. |
The two-dimensional kernel density estimation is done with the function kde2d in package MASS.
Plot with the 2-dimensional kernel densities and historgrams for the input variables.
Ana Casanueva, 13.12.2018
## Not run: # Generate data tas <- rnorm(1000, mean=15, sd=2) td <- rnorm(1000, mean=8, sd=1) # Plot 2-Dim Kernel density with histograms plotFun.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature", n.bins=25, add.contours=FALSE, title="2D density plot", cex.main=2) # add contours for the density values plotFun.kde2d.hist(var1=td, var2=tas, xlab="Dew point temp.", ylab="Air temperature", n.bins=25, add.contours=TRUE, title="2D density plot with contours", cex.main=2) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.