2013-10-27 2 views
1

텍스트 파일에있는 기능의 상위 10 개 값만으로 구성된 점 줄무늬를 만들고 싶습니다. 다음 코드는 작동하지만 출력은 160 개의 모든 변수가 포함 된 점선입니다.dotplot의 변수를 제한하는 방법은 무엇입니까?

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

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)}) 
관련 문제