I try to use a map created in ggplot to save as *pdf in order to create a georeferencing pdf using the function sf::st_write() without success. In my example:
#Packages
library(ggplot2)
library(ggspatial)
library(sf)
# Get data set - x any are the points
all.stands.predict<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/main/prediction__bug_2021-03-18.csv")
all.stands.predict<-all.stands.predict[all.stands.predict[,3]=="VILA PALMA",] # Area selection
#Create a map
(sites <- st_as_sf(all.stands.predict, coords = c("x", "y"),
crs = 4326, agr = "constant"))
gg <- ggplot() +
geom_sf(data=sites, color="red") +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.3, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) + #Add a north arrow
annotation_scale(location = "bl", width_hint = 0.55) + #Add a scale bar
xlab("Longitude") + ylab("Latitude") +
theme_bw()
# I inspected the map created
plot(gg)
#Save map as GeoPDF
st_write(gg, "mymap.pdf", driver = "pdf")
Obvisioly the output is:
Error in UseMethod("st_as_sf") :
method not applicable for 'st_as_sf' applied to a class object "c('gg', 'ggplot')"
Any many ways to convert the ggplot object to a sf object doesn't work too. I not try yet the use of the packages like RQGIS or RSAGA.
Please, there is some approach for creating easily GeoPDF maps using sf?
