Error with geom_sf()

ggplot2
#1

I'm trying to run the following code using the "world" dataset from spDataLarge:

library(sf)
library(spData)
library(spDataLarge)
library(dplyr)
library(ggplot2)
library(devtools)

devtools::install_github("Nowosad/spDataLarge")
devtools::install_github("tidyverse/ggplot2")

data(package = "spData")

ggplot(data = world) +
geom_sf()

I have no problems loading any of the libraries or data, but when I run the geom_sf() function, I get the following error:

Don't know how to automatically pick scale for object of type standardGeneric. Defaulting to continuous.
Error: All columns in a tibble must be 1d or 2d objects:

  • Column geometry is standardGeneric
    Call rlang::last_error() to see a backtrace

I have the latest version of R, and I've tried uninstalling and re-installing R and running the same code without any luck. Even after I run devtools::install_github("tidyverse/ggplot2"), the version of ggplot on my machine is 3.0, but I need 3.1 to run geom_sf(). Is there another way to install the development version of ggplot without using devtools::install_github("tidyverse/ggplot2")? Or, is there a different reason why I might be having this issue?

0 Likes

#2

Starting in a clean R session, what happens if you install.packages("ggplot2")?

Also, what's the output if you run .libPaths() in your console?

0 Likes

#3

I had no issues with install.packages("ggplot2").

The output for .libPaths() is:
"C:/Users/stote/OneDrive/Documents/R/win-library/3.5" "C:/Program Files/R/R-3.5.3/library"

I then re-ran devtools::install_github("tidyverse/ggplot2") and tried to run
ggplot(data = world) +
geom_sf()

again and got a new error message:

Error in FUN(X[[i]], ...) : object 'geometry' not found

0 Likes

#4

Why are you rerunning this after installing ggplot2 already? This is another way of installing a package. The version on CRAN is 3.1.0, so you should be fine with the CRAN version, and shouldn't need to install it again.

Error in FUN(X[[i]], ...) : object 'geometry' not found

Have you loaded your data in at this point?

Note that, in order to plot something with geom_sf() it needs to meet certain specifications/you need to tell it how to reference the information correctly. From

Geometry aesthetic

geom_sf() uses a unique aesthetic: geometry , giving an column of class sfc containing simple features data. There are three ways to supply the geometry aesthetic:

  • Do nothing: by default geom_sf() assumes it is stored in the geometry column.
  • Explicitly pass an sf object to the data argument. This will use the primary geometry column, no matter what it's called.
  • Supply your own using aes(geometry = my_column)

Unlike other aesthetics, geometry will never be inherited from the plot

1 Like

#5

Ahhh, I see. I didn't realize I didn't need to re-run the devtools line.

I started a new session of R and it worked. Thanks so much for your help!

1 Like

split this topic #7

5 posts were split to a new topic: Error in geom_sf(data = world, show.legend = F) : object '...' not found

0 Likes

closed #8

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes