x=cbind(1:4,3:6) png('one_point.png') plot(x[1:3,],xlim=c(-1,11),ylim=c(-1,11),pch=1) points(x[4,],pch=2)# this is plotted as two points #although I meant only one point legend("topleft", c("x","y"),pch=c(1,2)) dev.off() The above code will produce 5 points instead of 4 points. If I want to have 4 points, I have to use the following code. But the below code is a little bit tedious. I'm wondering if there is a way that I still use the above code (with a little change) to generate 4 points? x=cbind(1:4,3:6) png('one_point_split.png') plot(x[1:3,1],x[1:3,2],xlim=c(-1,11),ylim=c(-1,11),pch=1) points(x[4,1],x[4,2],pch=2) legend("topleft", c("x","y"),pch=c(1,2)) dev.off()
Richard M. Heiberger
2009-Oct-19 03:26 UTC
[R] Why points() is defined specially for a 1 by 2 matrix?
> points(x[4,],pch=2)# this is plotted as two pointsdrops what it sees as an unnecessary dimension. Use > points(x[4,, drop=FALSE], pch=2) See FAQ 7.5 tmp <- matrix(1:2) tmp tmp[,1] tmp[,1,drop=FALSE]