[R] Howto Smooth a Curve Created with the Point Function

Gundala Viswanath gundalav at gmail.com
Mon Aug 4 15:49:47 CEST 2008


Hi all,

I have this figure:

 http://docs.google.com/Doc?id=df5zfsj4_103rjt2v4d5

created with the following steps:

> x
  [1]  90.4  57.8  77.0 103.7  55.4 217.5  68.1  85.3 152.0 113.0  97.1  89.9
 [13]  68.1  83.7  77.4  34.5 104.9 170.3  88.6  88.1 108.8  77.4  85.6  82.7
 [25]  81.3 108.0  49.5  71.0  85.7  99.3 203.5 275.9  51.1  84.8  16.5  72.6
 [37] 160.5 158.3 136.7 140.0  98.4 116.1 177.0 168.7 208.0 219.3  90.5 119.7
 [49]  72.9 138.4  98.6  56.0 151.6 230.0  82.0  65.6  83.0 106.9 141.3 103.9
 [61]  76.0  90.6  72.9  85.5  70.5 134.3 129.5 130.9 187.1 131.4  57.7 179.7
 [73]  89.7 126.1 124.4 103.2 111.8 143.1  59.4  85.3 122.8 100.0 158.4 188.2
 [85]  91.9  90.0  74.5  70.2 105.8  90.0  96.6 109.5 176.8 145.1 126.2 215.9
 [97] 103.4 154.3  84.8 112.8 119.8 111.9 107.6 114.3 198.7  98.2 187.6 196.7
[109] 138.5 146.1  75.0  80.0 147.7 171.3  90.1  58.1 109.3 136.6  91.5  93.8
[121]  79.4  71.8

> xhist <- hist(x,col="blue", xlab="Exp Level",freq=FALSE)
> alpha <- 6.352082
> beta   <- 17.84647
> g.pdf <- dgamma(x,shape=alpha,scale=beta)
> points(x,g.pdf,col="red",type='l')  ## problem here

My question is:

Why the command "points" DOES NOT create smooth red curve
as we expected? How can I resolve this problem?

I specifically want to use the dgamma
function with the learned parameter (alpha,beta).

That's why I don't use this command:
> lines(density(x),add=T, col="red")


- Gundala Viswanath
Jakarta - Indonesia



More information about the R-help mailing list