如何限制dotplot的变量?

时间:2013-10-27 14:19:14

标签: r plot

我想创建一个dotplot,它只包含文本文件中功能的前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()

1 个答案:

答案 0 :(得分:1)

如果你加入reproducible example会很有帮助。我的猜测是,这可以通过简单地对数据框进行子集来完成,这样您就只包含前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)})