2013-11-21 106 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)