我试图在一个图中拟合 2 条曲线。一个图包含直方图,同一个图包含正态曲线,最后是核函数。但是,我不能在绘图上显示一个以上的图表,这就是我正在做的事情:
hist(index$lognr, breaks = 100, prob=T)
mean_DJ = mean(index$lognr, na.rm=T);
sd_DJ = sd(index$lognr, na.rm=T);
//For the normal curve
curve(dnorm(x, mean_DJ, sd_DJ), add=T, col = "grey", lwd = 2)
//For kernel density
lines(density(index$lognr, na.rm=T), col = "blue", lwd = 2)
//30 sample data pointsstructure(list(Date = structure(c(1398L, 1381L, 1376L, 1372L,
> structure(head(index_A, 30))
Date Close LogNR
1 9/24/2012 690.79 -0.013373028
2 9/21/2012 700.09 0.001987433
3 9/20/2012 698.70 -0.004854378
4 9/19/2012 702.10 0.000270653
5 9/18/2012 701.91 0.003039191
6 9/17/2012 699.78 0.012221048
7 9/14/2012 691.28 0.012079375
8 9/13/2012 682.98 0.019501346
9 9/12/2012 669.79 0.013830855
10 9/11/2012 660.59 -0.003249381
11 9/10/2012 662.74 -0.026356891
12 9/7/2012 680.44 0.006147243
13 9/6/2012 676.27 0.008971468
14 9/5/2012 670.23 -0.007047308
15 9/4/2012 674.97 0.014520368
16 8/31/2012 665.24 0.002061531
17 8/30/2012 663.87 -0.014357104
18 8/29/2012 673.47 -0.001972899
19 8/28/2012 674.80 -0.001303241
20 8/27/2012 675.68 0.018612831
21 8/24/2012 663.22 0.000889995
22 8/23/2012 662.63 -0.009372956
23 8/22/2012 668.87 0.019337473
24 8/21/2012 656.06 -0.013760331
25 8/20/2012 665.15 0.025952144
26 8/17/2012 648.11 0.018327423
27 8/16/2012 636.34 0.008696599
28 8/15/2012 630.83 -0.001362355
29 8/14/2012 631.69 0.002678948
30 8/13/2012 630.00 0.013262158