With DiagrammeR you can build a block diagram in stages, if necessary, rendering using render_graph. This can get a little cumbersome, though, if you're not diligent, as you can see with the trivial example below.
library(DiagrammeR)
graph <- create_graph()
df<-data.frame(id=1:100,age=rnorm(100,40,5))
head(df)
graph <- add_node(graph, node = "df")
graph <- add_node(graph, node = "df$age")
graph <- add_node(graph, node = "df$id")
breaks <- c(0,seq(20,60,by=5),Inf)
graph <- add_node(graph,node = "breaks")
df.cut <- data.frame(id = df$id,
interval = cut(df$age,breaks = breaks))
graph <- add_node(graph,
node = "df.cut")
graph <- add_node(graph,
node = "data.frame",
shape = "square")
graph <- add_node(graph,
node = "cut",
shape = "square")
graph <- add_edges(graph,
create_edges(
from = c("df","df"),
to = c("df$id","df$age"),
rel = "to_get",
arrowhead = "box")
)
graph <- add_edges(graph,
from = c("df$age", "breaks", "cut"),
to = c("cut", "cut", "df.cut"),
rel = c("to_get","to_get", "to_get"))
graph <- add_edges(graph,
from = c("df$id", "cut", "data.frame"),
to = c("data.frame", "data.frame", "df.cut"),
rel = c("to_get","to_get", "to_get"))
render_graph(graph)
