Plot SpatialPoints "ylim" behaviour incomprehensible

33 views Asked by At

I'm trying to plot a SpatialPoints object using the generic function from the Package graphics. The extent of the plot should be exactly the size of the outermost datapoints. Here's a simple example where the ratio of delta x over delta y (outermost values) is 1:

library(sp)
xydata <- as.matrix(cbind(c(1,1,2,2,1.5),c(1,2,2,1,1.5)))
xy_sp = SpatialPoints(xydata)
bbox(xy_sp)
# min and max for x and y coordinates are identical, i.e. apect ratio = 1

png("output.png", width = 500, height = 500, units = "px", type = "cairo" )
par(mar=c(0,0,0,0), xaxs = "i")
plot(xy_sp, xlim = c(1,2), ylim = c(1,2), pch = "X")
# the following lines should NOT be visible
abline(a = 1, b = 0); abline(a = 2, b = 0); abline(v = 1);abline(v = 2)
dev.off()

In my understanding, the resulting plot from the above script should produce a graphic where only 1 point is visible (coordinates 1.5,1.5) but all 4 "ablines" should be invisible. Why is this not the case?

the resulting plot

1

There are 1 answers

0
Spacedman On BEST ANSWER

Try with yaxs="i" as well as xaxs:

 par(mar=c(0,0,0,0), xaxs = "i", yaxs="i")

works for me...