Saturday 31 August 2013

R: using Matplot to plot multiple curves same graph and scale

R: using Matplot to plot multiple curves same graph and scale

I have a table: y
1 2 3 4 5 6
0.2414412019 0.5032905670 0.1956391677 0.0422788008 0.0081100844 0.0015289503
7 8 9 15 20 24
0.0003323805 0.0001329522 0.0001994283 0.0000664761 0.0000664761 0.0000664761
26 27 28 29 30 38
0.0009971415 0.0007312371 0.0023266636 0.0010636176 0.0004653327 0.0001329522
39 40 41 42
0.0001994283 0.0005318088 0.0003323805 0.0000664761
is.table(y)
[1] TRUE
Originally, if I want to create a plot, I could simply do plot(y), which
look likes this
However, now I would like to add another curve to this plot, i.e.
dpois(1:42, lambda = 10). And I would like to preserve the scale by using
matplot. But since y is a table not a vector, I have no idea how to use
matplot to solve the problem. I do not want to use par(new = T) blablabla,
since it doesnt always preserve the scale and I am working with many
tables with different length
Note: my goal is to reproduce the plot above (the vertical lines must be
preserved, I do not want histogram or bars. In other words, I wish the
table structure of y can be preserved) with an additional curve on the
same graph. Can I use matplot or other function to achieve this in R?
Data structure below
dput(y)
structure(c(0.241441201887921, 0.503290567041149, 0.195639167719205,
0.0422788007711228, 0.00811008442464934, 0.00152895034235192,
0.00033238050920694, 0.000132952203682776, 0.000199428305524164,
6.6476101841388e-05, 6.6476101841388e-05, 6.6476101841388e-05,
0.00099714152762082, 0.000731237120255268, 0.00232666356444858,
0.00106361762946221, 0.000465332712889716, 0.000132952203682776,
0.000199428305524164, 0.000531808814731104, 0.00033238050920694,
6.6476101841388e-05), class = "table", .Dim = 22L, .Dimnames =
structure(list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "15", "20",
"24", "26", "27", "28", "29", "30", "38", "39", "40", "41",
"42")), .Names = ""))

No comments:

Post a Comment