r-spatial / RQGIS3

GNU Lesser General Public License v3.0
69 stars 19 forks source link

Using RQGIS3 for create GeoPDF maps #29

Open Leprechault opened 3 years ago

Leprechault commented 3 years ago

I'd like to create a GeoPDF using a ggplot map output. In my example:

#Packages
library(ggplot2)
library(ggspatial)
library(sf)
library(RQGIS3)

# 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("Latitude") + ylab("Longitude") +
  theme_bw() 

# I inspected the map created
plot(gg))

image

Now, I need to know if there is any way using RQGIS3 for create a GeoPDF map using my gg object?