I'm trying to plot a correlation matrix in R with histograms on main diagonal using:
pairs(credit[,-(4:5)], diag.panel=panel.hist)
But I get
object 'panel.hist' not found
What's wrong?
Have you executed code to define the panel.hist function? As per the example in the pairs documentation (https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/pairs.html):
panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5) )
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)
}
You need to run this code to define the panel.hist function in your environment before referencing it in pairs()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With