[R] Lattice Histogram Scaling

Roger Koenker rkoenker at illinois.edu
Tue Aug 15 16:13:12 CEST 2017


My apologies,  the data can now be found at:

url <- "http://www.econ.uiuc.edu/~roger/research/ebayes/velo.d"
x <- scan(url,skip = 1)

If I could get each of the histograms to mimic what is produced by

hist(x, 100, freq = FALSE)

I’ve experimented with xlim, ylim, without success so far...

url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker at uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Urbana, IL 61801

> On Aug 14, 2017, at 8:36 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
> 
> Your example is not easily reproducible.
> The REBayes requires Rmosek which requires a system command MOSEK.
> Please try again with an example using data in base R.
> 
> Meanwhile, my guess is that you will need to do something like
> explicitly specifying xlim and ylim so all panels have the same
> limits.
> 
> On Mon, Aug 14, 2017 at 5:41 PM, Roger Koenker <rkoenker at illinois.edu> wrote:
>> I am trying to do some comparisons of density estimators using lattice.
>> The code below attempts to plot the same histogram in each panel and
>> then overplots a kernel estimate with different bandwidths. Finding
>> packet.number() was a bit arduous, but seems to do what I want.  My
>> concern now is that close examination of the 4 histograms reveals that
>> they are different even though they use the same data, and use the
>> same binning.  Can someone explain this, or better yet suggest a fix?
>> Admittedly, the kernel estimates are rather silly, they are just standing
>> in for something else that I would like to think is less silly.
>> 
>> Many thanks,
>> Roger
>> 
>> 
>> require(REBayes)  # Source for the velo data
>> require(lattice)
>> x <- velo
>> x <- x[!(x == 0)]
>> bandwidths <- (1:4)*10
>> lp <- histogram(~x|bw, nint = 100, border = grey(.9), col = grey(.9),
>>                type = "density", panel = function(x, bw = bandwidths, ...){
>>            panel.histogram(x, ...)
>>            f <- density(x, bw[packet.number()])
>>            panel.lines(f$x, f$y, col = "blue", lwd = 1.5)
>>            })
>> print(lp)
>> 
>> 
>> url:    www.econ.uiuc.edu/~roger            Roger Koenker
>> email    rkoenker at uiuc.edu            Department of Economics
>> vox:     217-333-4558                University of Illinois
>> fax:       217-244-6678                Urbana, IL 61801
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list