sf icon indicating copy to clipboard operation
sf copied to clipboard

plot(sfobject) is very slow with RStudio on MacOS

Open dmkaplan2000 opened this issue 1 month ago • 3 comments

I am in the middle of doing a class on GIS in R and all of the students who are using MacOS computers with RStudio are having trouble plotting sf objects. Even the simplest graphs are very very slow to be generated. The same graphs generated from the terminal on the same computer are very fast to open. The solution we have found is to open a quartz() window before launching the graph, but this is only a partial solution. The same graphs using terra open immediately, so there is some sort of interaction between sf, RStudio and MacOS that is slowing down the plots.

The class finishes tomorrow so if you have any debugging requests for the students using Macs, let me know.

Thanks, David

dmkaplan2000 avatar Dec 09 '25 12:12 dmkaplan2000

David, is this using ggplot?

edzer avatar Dec 09 '25 12:12 edzer

Sorry for the slow response, but I was occupied with the class. No, this was just using straight up plot(sfobject). We tried using ggplot and tmap also. tmap seemed to have the same issue, but ggplot seemed quicker. In essence the situation was:

plot(sfobject) # Extremely slow on all 4 Mac computers in the class when plotting to RStudio

quartz()
plot(sfobject) # Much quicker, but in a separate window outside RStudio

library(terra)
plot(vect(sfobject)) # Much quicker

Thanks!

dmkaplan2000 avatar Dec 11 '25 09:12 dmkaplan2000

And the data used can be found here: https://www.davidmkaplan.fr/classes/2023-plan-formation-ird/data.zip

download.file("https://www.davidmkaplan.fr/classes/2023-plan-formation-ird/data.zip","data.zip")
unzip("data.zip")
library(sf)
sfobject = st_read("data/zaf/gadm36_ZAF_0.shp")

dmkaplan2000 avatar Dec 11 '25 09:12 dmkaplan2000