Skip to content

geom_sf() "missing aesthetics: geometry" with tibble but not data frame #3391

@frankhecker

Description

@frankhecker

After using RStudio today to update all my packages, when using ggplot() and geom_sf() to plot geospatial data contained in a tibble I now get the error message "Error: stat_sf requires the following missing aesthetics: geometry". The error does not occur when using a regular data frame.

This is my first time submitting an issue for the tidyverse or R. I could not get reprex() to work, and could not understand how it is supposed to work, so I hope the following is what you are looking for. In my testing the first ggplot() succeeds, while the second fails with the error above.

library(ggplot2)
library(tibble)
library(sf)
library(maps)
us <- st_as_sf(map("state", plot = FALSE, fill = TRUE))
us_tbl <- as_tibble(us)
ggplot(data = us) + geom_sf()
ggplot(data = us_tbl) + geom_sf()

I am running RStudio Server on Ubuntu 18.04 LTS. When I load the sf library it produces the message "Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions