luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
347 stars 20 forks source link

Autoplot method for sfnetwork objects #86

Closed luukvdmeer closed 3 years ago

luukvdmeer commented 3 years ago

Is your feature request related to a problem? Please describe. Among others, the time series packages from Rob J Hyndman and co have a nice autoplot method, which allows to directly create a ggplot object. For example, the autocorrelation function of a time series can be plotted directly without any tuning:

library(feasts)
#> Loading required package: fabletools
library(tsibbledata)

aus_production %>% 
  ACF(Beer) %>% 
  autoplot()

Created on 2020-10-28 by the reprex package (v0.3.0)

See https://feasts.tidyverts.org/reference/autoplot.tbl_cf.html

Describe the solution you'd like It might be nice to have an autoplot method for sfnetwork objects, next to the base plot method. Low priority.

luukvdmeer commented 3 years ago

Implemented by @loreabad6

library(sfnetworks)
library(ggplot2)

autoplot(as_sfnetwork(roxel)) + ggtitle("Road network of Roxel")

Created on 2020-11-02 by the reprex package (v0.3.0)

luukvdmeer commented 3 years ago

Pushed to master. Thanks @loreabad6, looks great! See also the function reference.

idshklein commented 2 years ago

Is it possible to control aes of points and lines as arguments to autoplot, or does it require to recreate the plot? autoplot is very lean and it would be great to control the bit complex sfnetwork object form there

idshklein commented 2 years ago

Is it possible to control aes of points and lines as arguments to autoplot, or does it require to recreate the plot? autoplot is very lean and it would be great to control the bit complex sfnetwork object form there

found a very hacky solution, wouldn't advice to use it: net %E>% mutate(rn = row_number()) %>% filter(rn %in% 21:28) %N>% filter(!node_is_isolated()) %E>% { (.) %>% autoplot() + aes(color = (.) %>% as_tibble() %>% pull(rn) %>% factor()) }

agila5 commented 2 years ago

Hi @idshklein! I'm pretty sure that, at the moment, you cannot adjust the aesthetics of points and lines geometries using the default autoplot method. I think autoplot.sfnetwork was deliberately designed with some restrictions and it is suitable just for quick and simple visualisations.

In any case, I suggest you ask the same question in a new github issue since, IMO, your question/suggestion will be quickly forgotten if you only post it in a closed issue.