2015-04-12 27 views
0

更換標籤,我試了幾次,在情節符號來代替標籤欄(項目1,項目2,項目3,...)。我已經使用了LTM包。下面是代碼:與符號

fsc <- factor.scores(rasch(LSAT)) 
plot(fsc, include.items = TRUE) 

我想更換標籤,列在情節黑色子彈(符號),然後將其重命名爲A1,A2,A3,A4,A5。在這種情況下可以做到嗎?如果是的話,是否有可能使它們變色?

+1

請仔細閱讀[這](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610)約的方式,使得它問的問題方便人們幫助你。更多資源[here。](http://stackoverflow.com/help/how-to-ask) –

+0

這真的很清楚我的問題。 – user1309

+1

嗯,不是真的。 'label-columns'是什麼意思? 'fsc'中沒有這個名字。這些符號已經在劇情中。另外,請將'library('ltm')'添加到您的代碼中以使其他人可以重現。 –

回答

3

你可以讓自己的功能基礎上,plot.fscores()

方法添加文本如果您不希望以編程方式做到這一點,你可以使用函數的轉儲dump("plot.fscores"),並在「變化dumpdata.R」。

library(ltm) 
dump("plot.fscores") 
## now we can make the following changes to 'dumpdata.R': 

## 1. change the function name. I used 'myPlot.fscores' 

## 2. add formal arguments to the argument list so we can pass them 
## to text(). I added 
text.labels = NULL 
col.labels = NULL 

## 3. on line 28, change the entire line to 
text(Beta, rep_len(0L, length(Beta)), labels = text.labels, col = col.labels) 

現在我們可以試試看......

fsc <- factor.scores(rasch(LSAT)) 
myPlot.fscores(fsc, include.items = TRUE, 
    text.labels = rownames(fsc$coef), col.labels = seq_len(nrow(fsc$coef))) 

enter image description here

否則,您可以編寫一些代碼...

## copy plot.scores for modification 
ff <- plot.fscores 
## add an argument to ff() - I use 'text.labels' to avoid multiple matching 
fm <-formals(ff) 
formals(ff) <- append(fm, list(text.labels = NULL), length(fm)-1) 
## change the stripchart() call to a call to text() with out new argument 
body(ff)[[6]][[3]][[2]][[4]][[6]] <- quote(
    text(Beta, rep_len(0, length(Beta)), labels = text.labels) 
) 
## see if it works 
fsc <- factor.scores(rasch(LSAT)) 
ff(fsc, include.items = TRUE, text.labels = rownames(fsc$coef)) 

enter image description here

我會讓你去看看那個顏色。而且因爲遞歸我相當糟糕,所以除了手動調查函數體之外,我沒有更簡單的方法來找到body(ff)[[6]][[3]][[2]][[4]][[6]]。我知道有一個遞歸函數來定位函數體的一部分,但我現在不記得它的名字,並且沒有成功搜索。