I'd like to build a correlogram using R function pairs(). In the lower panel I want to represent high density plots generated with hexbin(). However, I have problems to locate the hexbin plots in proper position of lower panels.
This is the function to generate each hexbin plot:
density_pts<- function(x,y,...){
bin <- hexbin(x, y, xbins=50)
plot(bin, main="", xlab="", ylab="",legend=F,newpage = FALSE)
}
The problem is that each plot generated by density_pts does not fit lower panel boxes. Which parameters have I to use to correctly locate them?
Here and example of the problem:
data<-data.frame(A = sample(1:1000),B = sample(1:1000),C = sample(1:1000),D = sample(1:1000))
density_pts<- function(x,y,...){
bin <- hexbin(x, y, xbins=50)
plot(bin, main="", xlab="", ylab="",legend=F)
}
# default scatterplot
pairs(data,upper.panel = NULL)
# custom high density plot ::: problem :::
pairs(data,lower.panel=density_pts,upper.panel = NULL)
Many thanks in advance!