轮廓线和透视图误差用于内核密度估计

时间:2018-10-16 01:01:41

标签: r ggplot2 contour perspective kernel-density

因此,我想进行核密度估计并输出轮廓图和透视图。我非常想弄清楚轮廓图,但是当我运行下面的代码时遇到了一个错误。此外,就同一数据的透视图而言,我在网上找到的代码似乎不适用于我的数据集。我这样做的带宽是.5,.5。

countourist<- ggplot(df, aes(x = X, y = Y)) +
  geom_point() +
  xlim(-5, 5) +
  ylim(-5, 5)

countourist + stat_density_2d(aes(fill = stat(level)),
                              countour = TRUE, h = .5,.5, 
                              geom = "polygon")

样本数据:

structure(list(X = c(-0.0962590773067708, -1.18915207404317, 
0.706207022991542, 0.354207143877577, -0.81518898552579, 0.275541521081109, 
0.497855536939137, 0.645414156351502, -0.0122766542233017, 0.40578545233698, 
0.189360054285873, 0.253754051773016, -0.88127350804621, 0.485445084008632, 
0.276018362443043, 0.0145802591922327, -0.181071537886075, 0.121463173714344, 
-0.152709201805671, -0.338877208521439, -1.46948728986613, -2.02398725046067, 
-0.624336281672069, -1.62555577656191, -0.67130590447829, -0.0335257471517457, 
0.198179809536955, -0.63029273337944, -0.694460643800555, -0.411059118662514, 
0.221464974231996, 0.430316124954996, -1.6217665981342, -0.881526856414648, 
-1.3192875841495, 0.404600053659747, 1.12817344490934, 0.024248421312024, 
-0.399749792485403, 0.0857939068657727, -0.217844669409035, 0.101279872558566, 
0.291323502766035, -1.42132579845577, 1.2753388274467, -1.33076195534297, 
-1.46502902788164, -0.73855874296236, -1.0322620171297, 0.113170727116302
), Y = c(0.0632600046556984, -1.78280440755007, 2.82492518636035, 
1.68999775891935, -1.40182480306009, -0.0162214629216463, 1.00914182163537, 
0.258321598714745, 0.249412178294172, 0.505938493454907, 0.88745904296611, 
0.545487039522648, 0.205393499236483, 1.43415169211384, -0.0293576589272771, 
0.373169713548136, 0.462176118409707, -1.11661047785449, 0.0361289986559508, 
0.219314070361257, -1.72970101801671, -1.13555829290375, -0.257332488904325, 
-1.00336683254877, -2.24667782853137, 0.718672747346788, 0.381256786447137, 
-0.0897024758439116, 0.533411392798842, 0.712575478035058, 1.6809613554424, 
0.504565244422453, -0.0852144876427054, 0.229922323383187, 0.0269379632874171, 
0.644533564497338, 1.49725854460476, 0.382307653466023, -0.41280923134344, 
-0.666316793613442, 0.410058708890068, -0.354068636380733, 1.55419054704138, 
-1.0573192227978, 1.48806834104077, -1.57278080268752, -0.863516432481153, 
-0.908568905792217, -1.30139200592853, 0.896154050079126)), row.names = c(NA, 
-50L), class = c("tbl_df", "tbl", "data.frame"))

0 个答案:

没有答案