I'm attempting to create a raster layer of lizard location data. Everything seems to be working until my final line of code creating the raster:
# Create raster
utm.points <- cbind(data.TM$X, data.TM$Y) # create an object of UTMs dataframe
utm.locations <- SpatialPoints(utm.points, proj4string=CRS("+proj=utm +zone=12 +datum=NAD27")) # create a spatial projection
proj.lat.lon <- as.data.frame(spTransform(utm.locations, CRS("+proj=longlat +datum=NAD27"))) # transform UTMs to lat/lon
colnames(proj.lat.lon) <- c("x","y") # rename columns of lat/lon object
raster <- openmap(c(max(proj.lat.lon$y)+0.005, min(proj.lat.lon$x)-0.005), c(min(proj.lat.lon$y)-0.005, max(proj.lat.lon$x)+0.005), type = "bing")
raster.utm <- openproj(raster, projection = "+proj=utm +zone=12 +datum=NAD27 +units=m +no_defs") # create the raster
When I run the final line to create the raster.utm I get the following error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘xmax’ for signature ‘"data.frame"’
Here's a sample of my data if that helps
library(tidyverse)
library(janitor)
library(lubridate)
library(sp)
library(OpenStreetMap)
library(pbapply)
library(mgsub)
library(stringr)
library(data.table)
animal.ID<-c("TM 1","TM 1","TM 1","TM 1")
X<-c(489755 ,489792 ,489537 ,489505)
Y<-c(3722898 ,3722405 ,3722746 ,3722467)
data.TMex<-data.frame(animal.ID,X,Y)
utm.points <- cbind(data.TMex$X, data.TMex$Y) # create an object of UTMs dataframe
utm.locations <- SpatialPoints(utm.points, proj4string=CRS("+proj=utm +zone=12 +datum=NAD27")) # create a spatial projection
proj.lat.lon <- as.data.frame(spTransform(utm.locations, CRS("+proj=longlat +datum=NAD27"))) # transform UTMs to lat/lon
colnames(proj.lat.lon) <- c("x","y") # rename columns of lat/lon object
raster <- openmap(c(max(proj.lat.lon$y)+0.005, min(proj.lat.lon$x)-0.005), c(min(proj.lat.lon$y)-0.005, max(proj.lat.lon$x)+0.005), type = "bing")
raster.utm <- openproj(raster, projection = "+proj=utm +zone=12 +datum=NAD27 +units=m +no_defs")
autoplot.OpenStreetMap(raster.utm, expand = TRUE) + theme_bw() + theme(legend.position="bottom") +
theme(panel.border = suppressWarnings(element_rect(colour = "black", fill=NA, size=1))) +
geom_point(data=data.TMex, aes(X, Y, color= animal.ID), size = 3, alpha = 0.8) +
theme(axis.title = element_text(face="bold")) + labs(x="Easting", y="Northing") + guides(color=guide_legend("Identifier"))