sfnetworks for aggregating routes to flows #149
Replies: 2 comments 6 replies
-
Hi @shriv this is a good question and I've been wondering the same thing. Related issue: ropensci/stplanr#458 Documentation of another way of generating flows, using the Hypothesis: it can be done faster and more flexibly with
|
Beta Was this translation helpful? Give feedback.
-
Hi @shriv! First of all thank you for pointing us to your blogpost! It is a super nice example of From a strictly dataviz perspective (so not commenting on code optimization here 😅) I have a couple of points:
On top of this. I know that it is tricky to use ggplot with several color scales, i.e. giving a color legend for the points and another for the lines is not possible, unless some workarounds are used. Some options:
I played a bit with your code to generate the plot you attached to integrate the recommendations I listed here. ggplot() +
geom_sf(data = railway_net %>%
activate("edges") %>%
st_as_sf(),
size = 0.1) +
geom_sf(data = railway_net %>%
activate("edges") %>%
st_as_sf() %>%
mutate(row = row_number()) %>%
inner_join(flows_df, by = c("row" = "edge_paths")),
aes(colour = flow, size = flow)) +
scale_colour_viridis_c(
"Flow", limits = c(0,550), breaks = seq(100, 600, 100)
) +
scale_size_continuous(
"Flow", range = c(0.2, 1.25), breaks = seq(100, 600, 100),
limits = c(0,550)
) +
guides(colour = guide_legend(), size = guide_legend()) +
geom_sf(data = orig_dest %>% select(from_port) %>% distinct() %>% st_as_sf(),
aes(fill = "grey60"),
size = 4, stroke = 0.01, shape = 21) +
geom_sf(data = railway_net %>%
activate("nodes") %>%
st_as_sf() %>%
mutate(row = row_number()) %>%
inner_join(orig_dest, by = c("row" = "to_index")),
aes(fill = "red"),
size = 2.5, stroke = 0.01, shape = 21) +
scale_fill_identity(breaks = c("red", "grey60"),
labels = c("nearest rail port", "original port"),
guide = "legend",
name = "") I hope this is useful for you! I am very happy to keep exchanging ideas on your work and to hear your opinions too 😄 |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm a reasonably new user of this excellent package. My particular use case (for the moment) is creating visualisations of flows on a transport network. I've got a simple example of port to port rail flows written up here. Appreciate any thoughts, comments and critique :-)
Cheers!
Shrividya
Beta Was this translation helpful? Give feedback.
All reactions