I want to transform a specific dataset of spatial points to points in the centre of a raster. The result sould be spatial points and for each point in the original dataset a point in the centre of the raster.
I made this example code to get a better idea of the task.
library(raster)
library(plyr)
library(ggplot2)
library(viridis)
setwd("C:/Users/chris/Desktop/Regionaler Klimawandel und Gesundheit/Urban COPD/R/Data/")
getwd()
set.seed(55)
r <- raster(xmn= 800000,
xmx= 810000,
ymn= 7200000,
ymx= 7210000)
p <- as(r@extent, 'SpatialPolygons')
pts <- spsample(p, n = 100, "random")
pts$value <- runif(100, min=0, max=10)
df <- as.data.frame(pts)
ggplot(data= df, aes(x, y, fill =value))+
geom_point(shape = 21, size = 2)+
scale_fill_viridis()+
theme_minimal()

Thank you all!

