Created
June 26, 2018 15:29
-
-
Save yutannihilation/479cb5f254826915a7a3d36ff84b4b43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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...?") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: