1

我有一张桌子: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

最初,如果我想创建一个情节,我可以简单地做情节(y),看起来像这样 在此处输入图像描述

但是,现在我想在该图中添加另一条曲线,即dpois(1:42, lambda = 10). 我想通过使用 matplot 来保留比例。但由于 y 是表而不是向量,我不知道如何使用 matplot 来解决问题。我不想使用 par(new = T) blablabla,因为它并不总是保留比例,而且我正在使用许多不同长度的表

注意:我的目标是重现上面的图(必须保留垂直线,我不想要直方图或条形图。换句话说,我希望y可以保留 的表结构),并在同一张图上添加一条曲线。我可以使用 matplot 或其他函数在 R 中实现这一点吗?

下面的数据结构

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 = ""))
4

1 回答 1

2

这是你要找的吗?

在此处输入图像描述

如果是这样,您需要做的就是添加lines(dpois(1:42, lambda = 10)). 那是:

y = dput(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 = "")))

windows()
  plot(y)
  lines(dpois(1:42, lambda=10))

有关更多信息,请参见?lines

于 2013-08-31T23:26:44.330 回答