He all!
I'm new in R world and I think that this will be a stupid error:
I would like to project a raster representing my "study area" adding observations take from rgbif
.
First, I've take specie observations in the "study area" using a polygon:
wkt <- 'POLYGON((14.022120 41.583456,13.928857 41.610301,13.607180 41.789949,13.645924 42.021854,13.779864 42.029311,14.035472 41.823996,14.066175 41.751961,14.057895 41.614899,14.022120 41.583456))'
Picus_viridis <- occ_data(scientificName = "Picus viridis", geometry = wkt, return = "data", limit = 1999)
Picus_viridis<-Picus_viridis$data
Second, I've upload the raster, cropped it to the extension of interest and assigned a projection:
elev <- raster("data/gtopo30/gtopo30.tif")
elev_park <- crop(elev, extent(13.398953, 14.235655, 41.402820, 42.064252))
projection(elev_park) <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"
Than I've tried to plot the raster with the observation points using ggplot
but R said me the there is an error:
ggplot() +
geom_raster(elev_park, aes(x = x, y = y)) +
geom_point(aes(x = Picus_viridis$decimalLongitude, y = Picus_viridis$decimalLatitude))
Errore:
mapping
must be created byaes()
Does anyone know were the problem is?
raster GTOPO30:
> elev_park
class : RasterLayer
dimensions : 84, 112, 9408 (nrow, ncol, ncell)
resolution : 0.008333334, 0.008333334 (x, y)
extent : 13.30001, 14.23334, 41.40001, 42.10001 (xmin, xmax, ymin, ymax)
crs : NA
source : memory
names : gtopo30
values : 16, 2689 (min, max)