Open Maschette opened 6 days ago
Currently I don't identify many methods for SpatGraticule
objects, on terra so my workaround here would be converting it to SpatVector
and then using geom_spatvector()
, based on https://github.com/rspatial/terra/blob/43681fd1af25775ee1565a4fd1bb5b4830b1c985/R/graticule.R#L211-L212
library(terra)
#> terra 1.7.83
library(tidyterra)
#>
#> Adjuntando el paquete: 'tidyterra'
#> The following object is masked from 'package:stats':
#>
#> filter
library(ggplot2)
terra::lin
#> Error: 'lin' is not an exported object from 'namespace:terra'
lux <- terra::vect(system.file("ex/lux.shp", package = "terra"))
grat <- graticule(
lon = seq(5.5, 6.75, 0.25),
lat = seq(49.25, 50.25, 0.25),
crs = crs(lux)
)
# Convert to SpatVector (lines)
v <- vect()
v@ptr <- grat@ptr
v
#> class : SpatVector
#> geometry : lines
#> dimensions : 11, 3 (geometries, attributes)
#> extent : 5.5, 6.75, 49.25, 50.25 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +no_defs
#> names : h lon lat
#> type : <logical> <num> <num>
#> values : FALSE 5.5 NaN
#> FALSE 5.75 NaN
#> FALSE 6 NaN
ggplot(lux) +
geom_spatvector(fill = "orange") +
geom_spatvector(data = v, color = "blue", linetype = "dotted")
ggplot(lux) +
geom_spatvector(fill = "orange") +
geom_spatvector(data = v, color = "blue", linetype = "dotted") +
coord_sf(crs = 3035) +
ggtitle("With custom projection")
Created on 2024-11-28 with reprex v2.1.1
Maybe add vect.SpatGraticule
method to terra @rhijmans ?
I have added a vect<SpatGraticule>
method to terra 1.8-3. Thank you for suggesting it.
Hi, This may be covered by another function but I couldn't see it in your list of data types.
Is there a way to plot SpatGraticule with ggplot2?
thanks, Dale