0

According to the previous questions answered I thought the following script should work.

require(lattice)

histogram(cyl~mpg|gear*am,
        data=mtcars,
        nint=5,
        panel=function(y,...){
            panel.histogram(...)
            m<-mean(y)
            panel.txt(x=30,y=60,labels=m)
        }
)

The histograms plot but I'm getting the "packet 1 argument "y" is missing, with no default"

Help appreciated as I've wasted an hour of my life on this puzzle..

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
Markm0705
  • 1,340
  • 1
  • 13
  • 31
  • What value are you trying to print? A histogram plot is a univariate plot with no explicit `y` value (ie passing `cyl` here has no effect). – MrFlick Jun 15 '14 at 23:05

1 Answers1

0

panel.histogram needs an x argument (not a y argument) which is a clue that this is what histogram passes to the panel.

Also, you need to pass the x argument through to panel.histogram by including it in the argument list.

Finally, it's panel.text rather than panel.txt.

histogram(cyl~mpg|gear*am,
          data=mtcars,
          nint=5,
          panel=function(x, ...){
              panel.histogram(x=x,...)
              m<-mean(x)
              panel.text(x=30,y=60,labels=m)
          }
)

enter image description here

Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112