Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created June 26, 2018 15:29
Show Gist options
  • Select an option

  • Save yutannihilation/479cb5f254826915a7a3d36ff84b4b43 to your computer and use it in GitHub Desktop.

Select an option

Save yutannihilation/479cb5f254826915a7a3d36ff84b4b43 to your computer and use it in GitHub Desktop.
library(sf)
library(ggplot2)
do_bench <- function(n) {
d <- data.frame(
x = runif(n) * 360,
y = runif(n) * 180
)
d_sf <- st_multipoint(as.matrix(d)) %>%
st_sfc() %>%
st_cast("POINT")
result <- microbenchmark::microbenchmark(
plot(d),
print(ggplot(d) + geom_point(aes(x, y))),
plot(d_sf),
print(ggplot(d_sf) + geom_sf()),
times = 5
)
# as data.frame
result <- summary(result)
result$n <- n
result
}
x <- purrr::map_dfr(c(10, 50, 100, 500, 1000), do_bench)
x
ggplot(x, aes(n, median, colour = expr)) +
geom_linerange(aes(ymin = min, ymax = max)) +
geom_point() +
geom_line() +
theme_minimal() +
theme(legend.position = "top") +
ggtitle("Why geom_sf() is so slow...?")
@yutannihilation
Copy link
Author

Result:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment