2013-11-21 168 views
0

樣本數據/例如:劇情值

x <- log(seq(1,11,1)) 
y <- seq(0,1,0.1) 
plot <- xyplot(y~x, type="l") 
update(plot, panel = function(...) { 
panel.xyplot(...)})+as.layer(xyplot(y[3]~x[3], type=c("p"), lwd=3, cex=3, pch=3)) 

現在,讓我們說,我有點的一個新的測量,其中我的函數x輸出值2.5以上,像數字10我不得不保持初始繪圖軸在y = 0:1和x = 0:2,5。

如何以圖形方式顯示該值超出其繪圖範圍?有沒有辦法告訴/顯示值10存在?

我只是想過這個:

ifelse(x > 2.5, 2.5) 

這將帶來價值10至2.5,並在功能x的結束畫點。有沒有辦法「畫」 - 顯示異常值?

真實情況更復雜,因此簡化。暗示在哪裏看會有所幫助。

編輯:發表TWL解決方案給了我晶格中暗示:

tp <- sprintf("+ outlier") 

mypanel<-function(x,y,...){ 
panel.xyplot(x, y, ...) 
panel.text(2,1,labels=tp,cex=1.5,col="red")} 

xyplot(y~x, type="l", panel=mypanel) 
+0

只需要添加一個名爲離羣柱(或者其他),如果該值大於2.5,則將其設置爲true,然後將離羣值點繪製爲2.5,並使用不同的符號?也許用它的真實價值來標記它? –

回答

1

我可以提出一個替代方案,可能比使用點陣簡單:

x <- log(seq(1,11,1)) 
y <- seq(0,1,0.1) 

# set the margins and 'xpd' allows to plot outside the range 
par(mar=c(5,5,5,7), xpd=T) 

# plot the data within the range 
plot(x,y, type="l", col="blue", frame=F, xlim=c(0,2.5)) 
points(x[3],y[3], col="blue", pch=3, cex=2) 

# add the outlier by specifying the coordinate x and/or y outside the range 
points(2.9, 1, col='blue', pch=20, cex=2)