Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when plotting sf object --- Error: could not find function "geom_sf"

Tags:

r

ggplot2

I'm currently running R Version 3.3.3 on Windows and have ggplot2 version 2.2.1 and the sf package version 0.5-4 and am getting an error saying that R could not find the function "geom_sf."

I expected to find the function because it is listed in Tidyverse documentation at http://ggplot2.tidyverse.org/reference/ggsf.html.

The output of ls("package:ggplot2") did not show "geom_sf" as an included function and I could not find it in the library files.

Does anyone know how I might get this elusive package?

like image 545
Arcenis Rojas Avatar asked Sep 12 '17 20:09

Arcenis Rojas


People also ask

Why won't Geom_SF() work with my plot?

The problem is that geom_sf () doesn't have access to the plot data. However, it should work if you supply the data directly. Sorry, something went wrong. With which command? (I have had problems reproducing a case posted to r-sig-geo) Sorry, something went wrong. Your final example should work: Sorry, something went wrong.

What does “could not find function “ggplot”” mean?

Error in ggplot(df, aes(x = x, y = y)) : could not find function "ggplot" This error occurs when you attempt to create a plot using the ggplot2 data visualization package, but have failed to load the package first. This tutorial explains five potential ways to fix this error. How to Reproduce this Error. Suppose we run the following code in R:

Do nothing with Geom_SF ()?

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. Unlike other aesthetics, geometry will never be inherited from the plot. coord_sf () ensures that all layers use a common CRS.

What is the use of Geom_SF?

Visualise sf objects — ggsf This set of geom, stat, and coord are used to visualise simple feature (sf) objects. For simple plots, you will only need geom_sf() as it uses stat_sf() and adds coord_sf() for you. geom_sf() is an unusual geom because it will draw different...


1 Answers

While running R as the administrator, reinstall ggplot2 like this:

devtools::install_github("tidyverse/ggplot2")
require(ggplot2)

You should be able to see it now with ?geom_sf

For questions related to using devtools, see this SO answer.

like image 75
www Avatar answered Oct 22 '22 15:10

www