我有一个很大的数据集,我正在尝试用它离散化并创建一个3d曲面图:
rowColFoVCell wpbCount Feret
1 001001001001 1 0.58
2 001001001001 1 1.30
3 001001001001 1 0.58
4 001001001001 1 0.23
5 001001001001 2 0.23
6 001001001001 2 0.58我试图在第二列的基础上对第三个'Feret‘列进行离散化,因此对于每个'wpbCount’bin,'Feret‘列。
wpbCount Feret Count
1 1 [0.0,0.2] 3
2 1 [0.2,0.4] 5
3 1 [0.4,0.6] 6
4 1 [0.8,0.8] 9
5 2 [0.0,0.2] 6
6 2 [0.4,0.6] 23发布于 2013-12-31 12:23:11
这是对第一部分的回答:
创建一些数据
DF <- data.frame(wpbCount = sample(1:1000, 1000),
Feret = sample(seq(0, 1, 0.001), 1000))1)离散化使用 with right = FALSE,因此间隔是[)我通常觉得这比缺省值更有用
DF$cut_it <- cut(DF$Feret, right = FALSE,
breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1))2)聚合
TABLE <- data.frame(table(DT$cut\_it))编辑另一次尝试
library(data.table)
DT <- data.table(DF)
DT <- DT[, list(wpbCount = length(wpbCount),
Feret = length(Feret)
), by=cut_it]也许你只是想离散化,而不是聚合。试试这个:
DF2 <- data.frame(wpbCount = sample(1:3, 1000, replace=T),
Feret = sample(seq(0, 1, 0.001), 1000))
DF2$Feret2 <- cut(DF$Feret, right = FALSE,
breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1.1))
DF2 <- DF2[, c(1, 3)]发布于 2013-12-31 15:40:06
非常感谢你的帮助,我在R中使用了以下函数:
x$bin <- cut(x$Feret,right = FALSE,breaks = seq(0,max(wpbFeature$Feret),by=0.1))
Y <-aggregate(x$bin,by = xc('wpbCount','bin'),长度)
从你的建议中,我已经得到了我需要的数据框架:
wpbCount | bin |x
1[0.2,0.3] 72
2 [0.2,0.3) 142
3 [0.2,0.3) 224
4[0.2,0.3] 299
5 [0.2,0.3) 421
6[0.2,0.3] 479
现在我需要在3D中绘制它,我不确定如何使用非数值列,即bin列,它是因子。
有人知道我如何将这三列相互对比吗?
发布于 2013-12-31 17:08:13
看看这个link。这里有一些3d图。然而,3d绘图并不是分析数据的最好工具。如果您坚持使用3d方法,可以尝试ggplot2包中的stat_contout()。
然而,一个可能更好的方法是在2d中绘制几个图,或者使用facet_grid()。还可以看看ggplot2 current documentation。
根据您的上一个答案(未测试)尝试此方法:
ggplot(DF, aes(wpbCount , x)) +
geon_point() +
facet_grid(. ~ bin)其思想是使用factor变量(在本例中为bin)来对图进行分面。
https://stackoverflow.com/questions/20851362
复制相似问题