0
votes

I need to rotate the SpatialLines object by 90 and 180 degrees, and then plot the original SpatialLines object with the rotated SpatialLines objects.

However, plot function provides this error:

Error in plot.new() : figure margins too large

I am using RStudio. I tried to restart R Session, restart RStudio and manually zoom out a plot by going to Plots->Zoom Plot... But it does not help to fix the problem.

library(sp)
library(maptools)

x <- c(1,5,4,8)
y <- c(1,3,4,5)
xy <- cbind(x,y)
xy.sp = sp::SpatialPoints(xy)
spl <- sp::SpatialLines(list(Lines(Line(xy.sp), ID=i)))

# Rotation of a SpatialLines object
spl90 <- maptools::elide(spl, rotate=90, center=apply(bbox(spl), 1, mean))
spl180 <- maptools::elide(spl, rotate=180, center=apply(bbox(spl), 1, mean))

plot(spl)
plot(spl90)
plot(spl180)
1
No problems on RStudio 0.98 with R 3.1, sp 1.0 and maptools 0.8-29. Which of the three plots produces an error? What happens if you put x11() before the plot commands?koekenbakker
@koekenbakker: Thanks! Adding x11() before the plot command solved the problem.Klausos Klausos

1 Answers

1
votes

I sometimes get this error as well and I maximize my X11 plotting window and it goes away (I don't use RStudio often though). The code you provided works fine for me even in the default size viewer. This code produces 3 plots though. You could make them on the same plot by using the parameter new in par

plot(spl)
par(new=TRUE)
plot(spl90)
par(new=TRUE)
plot(spl180)
par(new=FALSE)

I would try writing to a file and see if that works.