I'm trying to use R to make some maps but I have having problems getting anything to generate. I took the following code from a post here:
library(ggplot2)
library(sf)
eng_reg_map <-
st_read("data/Regions_(December_2017)_Boundaries/Regions_(December_2017)_Boundaries.shp")
eng_reg_map |>
ggplot()
geom_sf(fill = "white",
colour = "black")
theme_void()
I have the relevant files in the right place, but when I run this code it just runs and never stops. I've waited for an hour.
Any help would be much appreciated.
CodePudding user response:
As discussed in the comments, I personally find this problem for one of two reasons.
The shapefile you want to plot is really large. It might not be surprising that R doesn't want to plot a 30 gigabyte shapefile, but it might be surprising to you that your file is that large. You can usually get around this by reducing the number of vertices, combining like shapes, filtering out some unnecessary features, etc.
You are trying to print the plot to the consol. For some reason, actually making the map is relatively fast, but displaying the map takes a really long time. I'm sure this varies computer by computer, but this has been my experience. In this case, it works best to save the plot as a pdf or something else and then view the plot outside of R.
CodePudding user response:
Thanks to user AndS for this solution
"I think the hang up might be printing the map to the consol. I find that you can easily create and export maps, but printing them can cause some issues. Maybe its because of my own computer set-up (low graphics or some such). Try assigning the map to a variable and saving it as a pdf. See if that speeds it up"