1

我想创建一个仅包含文本文件中特征的前 10 个值的点图。以下代码有效,但输出是包含所有 160 个变量的点图。

library(lattice)
table<-"imp_s2.txt"
DT<-read.table(table, header=T)
# output graph to pdf file 
pdf("dotplot_s2.pdf")
colnames(DT)

DT$feature <- reorder(DT$feature, DT$IncMSE)

dotplot(feature ~ IncMSE, data = DT,
        aspect = 1.5,
        xlab = "Variable Importance, Scale 2",
        scales = list(cex = .6),
        panel = function (x, y) {
          panel.abline(h = as.numeric(y), col = "gray", lty = 2)
          panel.xyplot(x, as.numeric(y), col = "black", pch = 16)})
dev.off()
4

1 回答 1

1

如果您包含一个可重现的示例,将会有所帮助。我的猜测是,这可以通过简单地对您的数据框进行子集化来完成,以便您只包含具有前 10 个值的行。像这样的东西可能会起作用(尽管我无法测试它):

# get threshold value
cutoff <- sort(DT$IncMSE, decreasing=TRUE)[10]

dotplot(feature ~ IncMSE, 
        data = DT[which(DT$IncMSE>=cutoff),], # this only includes top values
        aspect = 1.5,
        xlab = "Variable Importance, Scale 2",
        scales = list(cex = .6),
        panel = function (x, y) {
          panel.abline(h = as.numeric(y), col = "gray", lty = 2)
          panel.xyplot(x, as.numeric(y), col = "black", pch = 16)})
于 2013-10-27T14:43:30.243 回答