[R] density plot not smooth

S Ellison S.Ellison at LGCGroup.com
Wed Mar 18 11:14:02 CET 2015


>  I have a dataset with 6187 elements, ranged from 3 to 104028. When I tried to
> examine only small range of data, I found that the plot was not smooth (as
> shown below):
> plot(density(test$V2), xlim=c(0,1000))
> 
> 
>  Is there away to make it smoother?

For small ranges, use 'from' and 'to' in density() to restrict the range over which the density is calculated rather than increasing the number of points.

for example

plot(density(test$V2, from=0, to=1000))

This should produce a 512-point density plot for the region of interest only - though you may not find it very interesting for such a small range.... 

S Ellison


*******************************************************************
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK


More information about the R-help mailing list