【发布时间】:2016-02-01 15:37:42
【问题描述】:
我使用ggplot2 包为R 创建了一个密度图。我想确定图中出现在 0.01 和 0.02 之间的峰值/峰值。传说太多无法挑出,所以我删除了所有传说。我试图过滤掉我的数据,以找到一个组在 0.01 和 0.02 之间的大多数行数。然后我过滤掉选定的组以查看尖峰/峰值是否消失但没有,它仍然在那里绘制。您能否提出一种方法来识别这些图中的这些尖峰/峰值?
这里是一些代码:
ggplot(NumofHitsnormalized, aes(NumofHits_norm, fill = name)) + geom_density(alpha=0.2) + theme(legend.position="none") + xlim(0.0 , 0.15)
## To filter out the data that is in the range of first spike
test <- NumofHitsnormalized[which(NumofHitsnormalized$NumofHits_norm > 0.01 & NumofHitsnormalized$NumofHits_norm <0.02),]
## To figure it out which group (name column) has the most number of rows ##thus I thought maybe I could get the data that lead to spike
testMatrix <- matrix(ncol=2, nrow= length(unique(test$name)))
for (i in 1:length(unique(test$name))){
testMatrix[i,1] <- unique(test$name)[i]
testMatrix[i,2] <- nrow(unique(test$name)[i])}
康拉德,
这是我用极值包过滤掉我的数据后制作的新图。有新的峰值,它们位于不同的间隔,它还说 96% 的初始组在新图中有数据(尽管过滤数据中的行数减少到初始数据集的 0.023%)所以我无法确定哪个峰属于哪些组。
【问题讨论】:
-
我质疑“异常值”这个词。我似乎隐约记得一位著名的统计学家说过这样的话:“每当我看到一个非常出乎意料的结果时,我都不确定是否应该将其丢弃或申请专利。”。
-
当然可以显示一些代码???
-
看看
extremevalues(PDF) 包,它应该能满足您的需求。 -
添加到您的帖子中,而不是在评论部分中
-
你也可以看看 pastecs 包中的 turnpoints()
标签: r ggplot2 density-plot