I am trying to use geom_spatial_polygon
but regardless of the dataset I use, if my data is numeric, integer, factor or character, or if I start the plot with basemap()
or ggplot()
I receive the following error: Problem while converting geom to
grob.
ℹ Error occurred in the 1st layer.
Caused by error in as.vector()
:
! cannot coerce type 'closure' to vector of type 'character'
I would really appreciate any advice on how to fix this as I have been stuck here for over a week!
# creating data
lat<-c(80.30707, 80.29094, 80.29137, 80.29221,80.29109, 80.28888, 80.27666, 80.27193,80.23415, 80.22916, 80.21851, 80.20874)
long<-c(52.53969, 52.43050, 52.41305, 52.37471, 52.34166, 52.31138, 52.19777, 52.18138,52.33222, 52.47833, 52.49959, 52.61820)
group<-(rep(0.1,12))
df<-data.frame(lat, long, group)
df$group<-as.factor(df$group)
# loading packages
library(ggplot2)
library(ggOceanMaps)
# plot
basemap(limits=c(5,50,70,82))+
geom_spatial_polygon(data=df,aes(x=long,y=lat,group=group),color=NA,fill="lightblue") ```
#error message
Error in `geom_polypath()`:
! Problem while converting geom to
grob.
ℹ Error occurred in the 2nd layer.
Caused by error in `as.vector()`:
! cannot coerce type 'closure' to vector of type 'character'
Backtrace:
1. base (local) `<fn>`(x)
2. ggplot2:::print.ggplot(x)
4. ggplot2:::ggplot_gtable.ggplot_built(data)
5. ggplot2:::by_layer(...)
12. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
...
23. base::with.default(...)
24. base::eval(substitute(expr), data, enclos = parent.frame())
25. base::eval(substitute(expr), data, enclos = parent.frame())
26. base::paste(fill, colour, alpha, size, linetype)
28. base::as.character.default(`<stndrdGn>`)