I am an extreme beginner to R and coding in general I don’t even know what R is trying to tell me with that error message, I am trying to create a map of the coast with a series of points where sampling stations are located. Help would be greatly appreciated but please be patient considering how new to this I am.
Here is the code I am using
# --Loading Packages and external data--
library(tidyverse)
library(oce)
library(ocedata)
library(magrittr)
library(sf)
library(terra)
library(spData)
library(spDataLarge)
library(extrafont)
#install.packages("maps")
#install.packages("mapdata")
library(maps)
library(mapdata)
library(mapproj)
data(coastlineWorldFine)
font_import()
loadfonts()
help(as.data.frame)
# ----Creating Variables----
Station_Data <- read.csv("ph_station.csv", header = TRUE)
Station_Data
mapdata <- map_data("world")
This is the part where the code throws an error
"Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ‘"waiver"’ to a data.frame" coast <- as.data.frame(coastlineWorldFine@data) view(coast)
# ----Creating Pdf's and tables----
pdf(file = "sampling_map.pdf", width = 17, height = 10)
# ----Mapping----
ggplot()+
geom_polygon(data = coast, aes(x = longitude, y = latitude),
fill = "green4")+
coord_map(projection = "stereographic", ylim = c(44, 52), xlim = c(-73, -53))+
geom_point(data = Station_Data, aes(x = Longitude, y = Latitude, col = Cruise),
size = 8) +
scale_shape_manual(name = "Cruise", values = c(16))+
scale_colour_manual(name = "Cruise", values = c("red","purple"))+
theme_minimal()+
theme(text = element_text(color = "#22211d", size = 16),
axis.line = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "#ebebe5", size = 1.7),
panel.grid.minor = element_blank(),
plot.background = element_blank(),
panel.background = element_blank(),
legend.background = element_blank(),
legend.title = element_blank(),
legend.position = "bottom",
panel.border = element_rect(fill = NA, color = "#ebebe5", size = 1.7))
dev.off()
Welcome to SO, @Shmee_Diver! Do us a favor and
dput()
yourStation_Data
so we can help. Cheers!also if you could explicitly say which step is failing, the
coast<-
orstation_data<-
map_data<-` step, if it is coast<-dput(coastlineWorldFine@data)
toocannot reproduce –
pacman::p_load(ocedata); data(coastlineWorldFine); coastlineWorldFine@data |> as.data.frame()
works fine for me