library("ggflowchart")
library("readxl")Today I explore the ggflowchart package (made by Dr Nicola Rennie). For some data, the scenario comes from The Planet Crafter video game. Later in the game (minor spoiler), you can fire rockets into space to deliver and trade items for currency. Before then, these items are crafted out of materials that are gathered on the planet. The information comes from The Planet Crafter wiki page. This blog post is not meant to be an accurate guide for gameplay; I took some liberties (and also did not indicate the quantities of the ingredients) in this quick exploration.
Data
I transcribed information for the nodes and edges into an Excel spreadsheet for typing convenience.
edge_df <- readxl::read_xlsx("planet_crafter_trade_goods.xlsx", sheet = "edges")
node_df <- readxl::read_xlsx("planet_crafter_trade_goods.xlsx", sheet = "nodes")node_df# A tibble: 47 × 2
name stage
<chr> <chr>
1 bacteria sample craft
2 bioplastic nugget craft
3 chocolate craft
4 circuit board craft
5 cookie craft
6 fabric craft
7 flour craft
8 fusion energy cell craft
9 high quality food craft
10 iridium rod craft
# ℹ 37 more rows
edge_df# A tibble: 40 × 2
from to
<chr> <chr>
1 algae bacteria sample
2 water bottle bacteria sample
3 mushroom bioplastic nugget
4 silicon bioplastic nugget
5 water bottle bioplastic nugget
6 cocoa chocolate
7 aluminium circuit board
8 bioplastic nugget circuit board
9 iron circuit board
10 nitrogen cartridge circuit board
# ℹ 30 more rows
Network
Now let’s see if the main ggflowchart function will work well with this situation.
ggflowchart::ggflowchart(edge_df, node_df, fill = stage)
The code package did the job as prescribed correctly and quickly, but I had presented a situation that was slightly complicated for a default graph.
Customization
Next, we try to adjust the network presentation with some of the underlying tools in the igraph package.
ggflowchart(edge_df, node_df, fill = stage, horizontal = TRUE)
This graph is more readable. From here, one could explicity define where the nodes are (by x and y coordinates).
In the game’s jargon, it might have made more sense to group the materials by tiers (“T1”, “T2”, “T3”) and perhaps repeat nodes that are used in multiple crafting recipes.