[R] Need help putting histograms on the diagonal of a splom plot

Marc Paterno paterno at fnal.gov
Fri Aug 31 01:37:08 CEST 2007


I am in need of help in putting histograms on the diagonal of a plot 
produced with splom().

The plot matrix I am trying to produce is to have standard scatterplots 
in the upper-left triangle, contour plots in the lower-right triangle, 
and histograms on the diagonal. I have a function that does the first 
two, but the histograms on the diagonal has been beyond my ability.

Here is my function:

my.plot = function(data)
   splom( ~data
        , lower.panel=function(x,y, ...)
            panel.contourplot( xy.tr$x
                             , xy.tr$y
                             , xy.tr$z
                             , subscripts=seq(nrow(xy.tr))
                             , contour=TRUE
                             , region=TRUE
                             , labels = FALSE
                             , col.regions = terrain.colors
         , upper.panel=function(x,y, ...)
            panel.xyplot(x,y, cex=0.5)
        #, diag.panel=function(x, ...)
        #  {
        #    panel.histogram(x, ...)
        #  }

It can be called, for example, with:

   my.plot(subset(iris, select = Sepal.Length:Petal.Width))

(the subset is necessary to get rid of a variable that is a factor; my 
function can not deal with factors).

I have commented out my best guess at the code needed to produce the 
histograms along the diagonal, which fails.

Any guidance would be greatly appreciated.

best regards,

More information about the R-help mailing list