-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Hi,
I thought it would be nice to be able to automatically plot a gadget model. Thought of basing this on g3_fit object. This is as far as I got for now. Posting it here in case someone gets inspired to continue. If not, I'll continue next year.
library(dplyr)
library(DiagrammeR)
stocks <- fit$res.by.year %>%
filter(year == max(year)) %>%
mutate(size = total.biomass/sum(total.biomass),
type = "stock") %>%
rename("name" = "stock") %>%
dplyr::select(name, type, size)
fleets <- fit$fleet.info %>%
filter(year == max(year)) %>%
mutate(size = amount/sum(amount),
type = "fleet") %>%
rename("name" = "fleet") %>%
dplyr::select(name, type, size)
predation <- optim_fit$suitability %>%
dplyr::ungroup() %>%
dplyr::filter(suit > 0) %>%
dplyr::select(stock, fleet) %>%
dplyr::distinct()
graph <- create_graph()
## ####
graph %>%
add_nodes_from_table(
table = bind_rows(stocks, fleets) %>% rename("value" = "size"),
label_col = name,
type_col = type
) %>%
add_edges_from_table(
table = predation,
from_col = stock,
to_col = fleet,
from_to_map = label
) %>%
set_node_attrs(
node_attr = 'fontcolor',
values = 'black'
) %>%
select_nodes(type == "stock") %>%
set_node_attrs_ws(
node_attr = fillcolor,
value = "orange") %>%
set_node_attrs_ws(
node_attr = shape,
value = "rectangle") %>%
set_node_attrs_ws(
node_attr = y,
value = 4) %>%
clear_selection() %>%
render_graph("tree")Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels