Hi Jim
Without going to the histogram function to study it in detail it appears
when there is density used in the histogram function the data has to be in
the original scale to to send to the panel function.
As you example is not reproducible use the singer data to get the ylimits
for the histogram and density plot separately
For density
d <-
histogram( ~ height | voice.part, data = singer,
xlab = "Height (inches)", type = "density",
panel = function(x, ...) {
# panel.histogram(x, ...)
panel.abline(v= 70)
panel.mathdensity(dmath = dnorm, col = "black",
args = list(mean=mean(x),sd=sd(x)))
} )
d$y.limits ...
and the same for the histogram with type = percent
if you divide the last by the former there is a difference of 192 (ie
scaling factor)
Using the full dataset as it is quicker to demonstrate
histogram( ~ height, data = singer,
type = "percent", border = "transparent", col.line = "grey60",
xlab = "Height (inches)",
ylab = "Density Histogram\n with Normal Fit" )
trellis.focus("panel", 1, 1, clip.off=F, highlight = FALSE)
llines(density(singer$height)$x, density(singer$height)$y*192)
trellis.unfocus()
This will give you the idea that it is possible. y axes labels etc are all
funny now
By using a user defined panel function plotting the histogram and the
density output plotted as panel.lines after scaling within the function you
should be able to get a plot
It may be easier to start off with an xyplot to send the data to the panel
function as you will need 2 types of data as original and that for the
histogram.
Whether you need to use panel.groups is another mater
HTH
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home:
mac...@northnet.com.au