[R] histogram

Peter Ehlers ehlers at ucalgary.ca
Thu Apr 15 12:11:13 CEST 2010


On 2010-04-15 3:35, Santosh wrote:
> Thanks for your email... yes, I had tried that "bw" thing.. for some reason
> it does not seem to work.. could not figure out where I am wrong...
>
> Below is an example for your convenience.. you might notice that the density
> plots appear to be a curve of connected segments. Changing breaks, nint or
> bw didn't seem to help.
>
> ############
> library(reshape)
> set.seed(13454)
> aa<-
> data.frame(a1=rnorm(500),b1=rnorm(500,0.8),c1=rnorm(500,0.5),cat1=rep(1:5,each=100))
> ab<- melt(aa,measure.vars=c("a1","b1","c1"))
> histogram(~
> value|variable,ab,breaks=NULL,nint=10,type="density",layout=c(2,2),as.table=T,scales=list(relation='free'),
>              panel=function(x,lqp=c(0.05,0.975),...) {
>              panel.histogram(x,col='lightblue',...)
>              panel.densityplot(x,col.line='blue',lwd=1.75,bw=2,...)
>              panel.abline(v=c(quantile(as.vector(x),prob=lqp,na.rm = T)),
>              col="dark green",lwd=2,lty=2)
>              },
>              strip=strip.custom( strip.names=F,
>                                  strip.levels=T,
>                                  par.strip.text=list(cex=0.75)),
> )
>
> ############

You need to supply a *list* 'darg' to panel.densityplot; see
the help page.

  panel.densityplot(x, darg = list(bw = "nrd", adjust = 1.2), ...)

(I would use one of the built-in bandwidth selectors with a
suitable 'adjust' value.)

  -Peter Ehlers

>
> Thanks again,
> Santosh
> On Thu, Apr 15, 2010 at 12:41 AM, Paul Hiemstra<p.hiemstra at geo.uu.nl>wrote:
>
>> Santosh wrote:
>>
>>> Dear R gurus...
>>>
>>> How do I control "smoothing" of a density plot in panel.densityplot when
>>> using histogram?
>>>
>>> Thanks much,
>>> Santosh
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> 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.
>>>
>>>
>> Hi,
>>
>>  From ?panel.densityplot, argument darg, I was referred to ?density. I think
>> the 'bw' argument is what you need. Pass it to panel.densityplot in the darg
>> argument.
>>
>> cheers,
>> Paul
>>
>>
>> --
>> Drs. Paul Hiemstra
>> Department of Physical Geography
>> Faculty of Geosciences
>> University of Utrecht
>> Heidelberglaan 2
>> P.O. Box 80.115
>> 3508 TC Utrecht
>> Phone:  +3130 274 3113 Mon-Tue
>> Phone:  +3130 253 5773 Wed-Fri
>> http://intamap.geo.uu.nl/~paul<http://intamap.geo.uu.nl/%7Epaul>
>> http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
>>
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list