I have a dataframe with the latitude and longitudes of lakes I wanted to plot on a map of northeast USA. I'm following this tutorial on how to create maps and plot them.
I can run the code (below) just fine as featured in the tutorial link.
library (ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
world <- ne_countries(scale = "medium", returnclass = "sf")
(sites <- data.frame(longitude = c(-80.144005, -80.109), latitude = c(26.479005, 26.83)))
ggplot(data = world) +
geom_point(data = sites, aes(x = longitude, y = latitude), size = 4,
shape = 23, fill = "darkred") +
coord_sf(xlim = c(-88, -78), ylim = c(24.5, 33), expand = FALSE)
but when I personalize the code for my dataset containing a latitude and longitude column for several lakes in New England, USA, I get an error:
My dataframe of lat and long:
LAT_DD83 LON_DD83
23 41.37213 -71.56798
34 42.33589 -71.90907
39 41.51963 -71.76691
62 41.78447 -71.64064
76 43.93213 -70.62131
129 41.41433 -71.54638
My code:
ggplot(data = world) + geom_sf() +
geom_point(data = lat_lon, aes(x = LON_DD83, y = LAT_DD83), size = 4, shape = 23, fill = "darkred") +
coord_sf(xlim = c(-80, -65), ylim = c(40, 50), expand = FALSE)
ERROR received:
#Error in st_cast.POINT(x[[1]], to, ...) : cannot create MULTILINESTRING from POINT
I don't quite understand what this error means. What am I missing?