[R] how to plots two pairwise data sets into a same graph

Xin
Mon, 05 May 2008 11:47:04 -0000

Dear all:

   I fitted "Observed" into a distribution as frequency. The predicted
values are calculated as "predicted" for frequency. bins is
"x". I plot observed, predicted against x in a graph. the commond is
here.

pts=barplot(observed,xlab="points",ylab="Frequency",ylim=c(0,300),xlim=c(2,52),axes=FALSE,border=TRUE,names.arg=x,col="white")
lines(spline(pts,predicted,n=300,method="natural"),type="l",lty=5)

However, I also want to plot the corresponding distribution. Then I calculated
"fits" for "x-fits". But I want to plot x-fits against fits
on the same graph with the obove one. The problem is the number of data points
are different for these two data set. This is because one is barplot for
frequency and the other is distribution.

Anyone has expreience on this?

Many thanks!


Xin

observed = c(139, 235, 172, 148, 105, 107, 79, 57, 49, 42, 46, 32, 21, 21, 15,
17, 17, 12, 13, 14, 9, 5, 2, 2, 8, 3, 1, 2, 6, 4, 7, 3, 1, 0, 1, 3, 2, 2, 2, 0,
1)
predicted=c(139.0049754, 246.8969138, 168.1220396, 131.3463461, 106.8035411,
88.59003341, 74.36727745, 62.93036472, 53.5594173, 45.78162026, 39.265666,
33.76844232, 29.10540287, 25.13283707, 21.73661786, 18.82471128, 16.32199011,
14.16652343, 12.30684833, 10.69991713, 9.309522357, 8.10506821, 7.06059872,
6.154019632, 5.366468978, 4.681803382, 4.086175589, 3.567684717, 3.116085024,
2.722542191, 2.379428444, 2.080149676, 1.818999049, 1.59103266, 1.391963648,
1.218071785, 1.06612614, 0.933318768, 0.817207779, 0.715668363, 0.626850614)
x=c(0,1,6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91,
96, 101, 106, 111, 116, 121, 126, 131, 136, 141, 146, 151, 156, 161, 166, 171,
176, 181, 186, 191, 196)

x-fits=c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144,
145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
200)

fits=c(139.0049754, 62.40580735, 53.21947643, 47.55494589, 43.46264373,
40.25404036, 37.6105092, 35.3596146, 33.39787351, 31.6584273, 30.09561497,
28.67687115, 27.37814683, 26.18116622, 25.07170369, 24.03845821, 23.07229322,
22.16570853, 21.31246426, 20.50730718, 19.74576789, 19.02400775, 18.33870169,
17.68694733, 17.06619345, 16.47418319, 15.90890847, 15.36857298,
14.85156196, 14.35641729, 13.88181676, 13.42655678, 12.9895378, 12.56975199,
12.16627269, 11.77824546, 11.40488028, 11.04544489, 10.69925898, 10.36568906,
10.04414408, 9.734071494, 9.434953795, 9.146305489, 8.867670371, 8.598619109,
8.33874708, 8.087672439, 7.845034369, 7.610491522, 7.383720591, 7.164415033,
6.952283898, 6.74705077, 6.548452799, 6.356239818, 6.17017353, 5.990026769,
5.815582817, 5.646634775, 5.482984982, 5.324444485, 5.170832536, 5.021976143,
4.877709635, 4.737874271, 4.602317873, 4.47089448, 4.343464029, 4.219892056,
4.100049417, 3.983812025, 3.871060607, 3.761680469, 3.655561285, 3.55259689,
3.45268509, 3.355727481, 3.261629279, 3.170299159, 3.081649105, 2.995594265,
2.912052815, 2.830945832, 2.752197171, 2.67573335, 2.601483442, 2.529378968,
2.459353799, 2.391344064, 2.32528806, 2.261126163, 2.198800752, 2.13825613,
2.079438448, 2.02229564, 1.966777349, 1.912834869,
1.860421078, 1.809490386, 1.759998674, 1.711903242, 1.665162757, 1.619737205,
1.575587846, 1.532677161, 1.490968819, 1.450427629, 1.411019502, 1.372711411,
1.335471359, 1.299268338, 1.264072301, 1.229854123, 1.196585576, 1.164239295,
1.13278875, 1.10220822, 1.072472763, 1.043558192, 1.015441053, 0.988098593,
0.961508748, 0.93565011, 0.910501915, 0.886044016, 0.862256865, 0.839121494,
0.816619499, 0.794733017, 0.773444714, 0.752737763, 0.732595833, 0.713003073,
0.693944093, 0.675403954, 0.65736815, 0.639822599, 0.622753627, 0.606147956,
0.589992693, 0.574275316, 0.558983664, 0.544105928, 0.529630636, 0.515546647,
0.501843136, 0.488509592, 0.475535801, 0.462911841, 0.450628073, 0.438675132,
0.427043919, 0.415725591, 0.404711559, 0.393993475, 0.383563226, 0.373412929,
0.363534923, 0.353921762, 0.34456621, 0.335461235, 0.326599999, 0.317975859,
0.309582356, 0.301413212, 0.293462323, 0.285723758,
0.278191749, 0.270860689, 0.263725127, 0.256779764, 0.250019447, 0.243439165,
0.237034049, 0.230799361, 0.224730497, 0.218822977, 0.213072449, 0.207474676,
0.202025541, 0.19672104, 0.191557277, 0.186530466, 0.181636922, 0.176873063,
0.172235405, 0.167720559, 0.163325229, 0.159046208, 0.154880378, 0.150824705,
0.14687624, 0.143032112, 0.139289529, 0.135645775, 0.132098209, 0.128644259,
0.125281426, 0.122007276, 0.118819445)



	[[alternative HTML version deleted]]