Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Histogram on main diagonal of pairs function in R

Tags:

r

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?

like image 931
EanX Avatar asked Oct 18 '25 01:10

EanX


1 Answers

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()

like image 137
Nat Avatar answered Oct 19 '25 16:10

Nat