我试着计算ggplot 2提供的faithfuld数据集中的密度列,发现计算结果与使用MASS中的ken 2d函数不同,我没有找到任何信息它是如何在faithfuld中计算的,你能解释为什么会发生这种情况吗?
library(ggplot2)
library(MASS)
attach(faithfuld)
head(faithfuld)
#> # A tibble: 6 × 3
#> eruptions waiting density
#> <dbl> <dbl> <dbl>
#> 1 1.6 43 0.00322
#> 2 1.65 43 0.00384
#> 3 1.69 43 0.00444
#> 4 1.74 43 0.00498
#> 5 1.79 43 0.00542
#> 6 1.84 43 0.00574
kde2d(eruptions, waiting)$z
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.001581071 0.002335108 0.002734390 0.002856616 0.002878211 0.002880409
#> [2,] 0.002335108 0.003448757 0.004038463 0.004218981 0.004250875 0.004254120
#> [3,] 0.002734390 0.004038463 0.004729004 0.004940389 0.004977736 0.004981536
#> [4,] 0.002856616 0.004218981 0.004940389 0.005161222 0.005200239 0.005204209
#> [5,] 0.002878211 0.004250875 0.004977736 0.005200239 0.005239550 0.005243551
#> [6,] 0.002880409 0.004254120 0.004981536 0.005204209 0.005243551 0.005247554
#> [7,] 0.002880537 0.004254310 0.004981759 0.005204441 0.005243784 0.005247788
#> [8,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [9,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [10,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [11,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [12,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [13,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [14,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [15,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [16,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [17,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [18,] 0.002880541 0.004254316 0.004981766 0.005204449 0.005243792 0.005247796
#> [19,] 0.002880537 0.004254310 0.004981759 0.005204441 0.005243784 0.005247788
#> [20,] 0.002880409 0.004254120 0.004981536 0.005204209 0.005243551 0.005247554
#> [21,] 0.002878211 0.004250875 0.004977736 0.005200239 0.005239550 0.005243551
#> [22,] 0.002856616 0.004218981 0.004940389 0.005161222 0.005200239 0.005204209
#> [23,] 0.002734390 0.004038463 0.004729004 0.004940389 0.004977736 0.004981536
#> [24,] 0.002335108 0.003448757 0.004038463 0.004218981 0.004250875 0.004254120
#> [25,] 0.001581071 0.002335108 0.002734390 0.002856616 0.002878211 0.002880409
#> [,7] [,8] [,9] [,10] [,11] [,12]
#> [1,] 0.002880537 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541
#> [2,] 0.004254310 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316
#> [3,] 0.004981759 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766
#> [4,] 0.005204441 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449
#> [5,] 0.005243784 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792
#> [6,] 0.005247788 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796
#> [7,] 0.005248022 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030
#> [8,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [9,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [10,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [11,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [12,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [13,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [14,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [15,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [16,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [17,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [18,] 0.005248030 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [19,] 0.005248022 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030
#> [20,] 0.005247788 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796
#> [21,] 0.005243784 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792
#> [22,] 0.005204441 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449
#> [23,] 0.004981759 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766
#> [24,] 0.004254310 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316
#> [25,] 0.002880537 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541
#> [,13] [,14] [,15] [,16] [,17] [,18]
#> [1,] 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541
#> [2,] 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316
#> [3,] 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766
#> [4,] 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449
#> [5,] 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792
#> [6,] 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796
#> [7,] 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030
#> [8,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [9,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [10,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [11,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [12,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [13,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [14,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [15,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [16,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [17,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [18,] 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038 0.005248038
#> [19,] 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030 0.005248030
#> [20,] 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796 0.005247796
#> [21,] 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792 0.005243792
#> [22,] 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449 0.005204449
#> [23,] 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766 0.004981766
#> [24,] 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316 0.004254316
#> [25,] 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541 0.002880541
#> [,19] [,20] [,21] [,22] [,23] [,24]
#> [1,] 0.002880537 0.002880409 0.002878211 0.002856616 0.002734390 0.002335108
#> [2,] 0.004254310 0.004254120 0.004250875 0.004218981 0.004038463 0.003448757
#> [3,] 0.004981759 0.004981536 0.004977736 0.004940389 0.004729004 0.004038463
#> [4,] 0.005204441 0.005204209 0.005200239 0.005161222 0.004940389 0.004218981
#> [5,] 0.005243784 0.005243551 0.005239550 0.005200239 0.004977736 0.004250875
#> [6,] 0.005247788 0.005247554 0.005243551 0.005204209 0.004981536 0.004254120
#> [7,] 0.005248022 0.005247788 0.005243784 0.005204441 0.004981759 0.004254310
#> [8,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [9,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [10,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [11,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [12,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [13,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [14,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [15,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [16,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [17,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [18,] 0.005248030 0.005247796 0.005243792 0.005204449 0.004981766 0.004254316
#> [19,] 0.005248022 0.005247788 0.005243784 0.005204441 0.004981759 0.004254310
#> [20,] 0.005247788 0.005247554 0.005243551 0.005204209 0.004981536 0.004254120
#> [21,] 0.005243784 0.005243551 0.005239550 0.005200239 0.004977736 0.004250875
#> [22,] 0.005204441 0.005204209 0.005200239 0.005161222 0.004940389 0.004218981
#> [23,] 0.004981759 0.004981536 0.004977736 0.004940389 0.004729004 0.004038463
#> [24,] 0.004254310 0.004254120 0.004250875 0.004218981 0.004038463 0.003448757
#> [25,] 0.002880537 0.002880409 0.002878211 0.002856616 0.002734390 0.002335108
#> [,25]
#> [1,] 0.001581071
#> [2,] 0.002335108
#> [3,] 0.002734390
#> [4,] 0.002856616
#> [5,] 0.002878211
#> [6,] 0.002880409
#> [7,] 0.002880537
#> [8,] 0.002880541
#> [9,] 0.002880541
#> [10,] 0.002880541
#> [11,] 0.002880541
#> [12,] 0.002880541
#> [13,] 0.002880541
#> [14,] 0.002880541
#> [15,] 0.002880541
#> [16,] 0.002880541
#> [17,] 0.002880541
#> [18,] 0.002880541
#> [19,] 0.002880537
#> [20,] 0.002880409
#> [21,] 0.002878211
#> [22,] 0.002856616
#> [23,] 0.002734390
#> [24,] 0.002335108
#> [25,] 0.001581071
创建于2023-04-03带有reprex v2.0.2
1条答案
按热度按时间qaxu7uf21#
ggplot2提供的
faithfuld
数据集计算如下:你可以在GitHub页面上找到这些信息:https://github.com/tidyverse/ggplot2/blob/main/data-raw/faithfuld.R