library("DiagrammeR")
grViz (width = 400, height = 400, "digraph boxes_and_circles {
graph [overlap = true]
node [shape = circle] a; b; c; a->c; b->c
}")
library("DiagrammeR")
nodes_simple <- create_nodes (nodes = c("a", "b", "c"))
edges_simple <- create_edges (from = c("a","b"), to = c("c","c"))
graph_simple <- create_graph (nodes_df = nodes_simple, edges_df = edges_simple)
render_graph(graph_simple, width = 400, height = 400)
library("DiagrammeR")
nodes_simple <- create_nodes (nodes = c("a", "b", "c"))
edges_simple <- create_edges (from = c("a","b"), to = c("c","c"))
graph_simple <- create_graph (nodes_df = nodes_simple, edges_df = edges_simple)
render_graph(graph_simple, output = "vivagraph")
library("DiagrammeR")
nodes_simple <- create_nodes (nodes = c("a", "b", "c"))
edges_simple <- create_edges (from = c("a","b"), to = c("c","c"))
graph_simple <- create_graph (nodes_df = nodes_simple, edges_df = edges_simple)
render_graph(graph_simple, output = "visNetwork")
library("DiagrammeR")
grViz("
digraph boxes_and_circles {
graph [overlap = true, fontsize = 10]
node [shape = box, fontname = Helvetica]
出張
二日酔い
node [shape = circle, fontname = Helvetica]
暑い
ビール飲みたい
賢者モード
研究しないと
暑い->ビール飲みたい
出張->ビール飲みたい
ビール飲みたい->二日酔い [label=飲む]
二日酔い->賢者モード [label=出す]
賢者モード->研究しないと
研究しないと->出張
}
")
library ("DiagrammeR")
grViz ("
digraph boxes_and_circles {
graph [overlap = true, fontsize = 10, layout = neato]
node [shape = box, fontname = Helvetica]
出張 [pos='-4,3!']
二日酔い [pos='0,-2!']
node [shape = circle, fontname = Helvetica]
暑い [pos='4,1!']
ビール飲みたい [pos='0,0!']
賢者モード [pos='-4,-2!']
研究しないと [pos='-4,1!']
暑い->ビール飲みたい
出張->ビール飲みたい
ビール飲みたい->二日酔い [label=飲む]
二日酔い->賢者モード [label=出す]
賢者モード->研究しないと
研究しないと->出張
}
")
The birthwt data frame has 189 rows and 10 columns. The data were collected at Baystate Medical Center, Springfield, Mass during 1986.
http://d.hatena.ne.jp/dichika/20151208/p1
## term estimate std.error statistic p.value conf.low
## 1 (Intercept) 1.0627985 0.75731970 0.08042249 0.93590124 0.2426549
## 2 age 0.9514394 0.03197195 -1.55696724 0.11947826 0.8918117
## 3 smoke 1.9974047 0.32180606 2.14989327 0.03156366 1.0641120
## conf.high
## 1 4.780114
## 2 1.011394
## 3 3.770397
library ("broom")
library ("DiagrammeR")
res_glm <- glm(data=MASS::birthwt, low~age+smoke, family="binomial")
(res_glm_tidy <- tidy(res_glm, exponentiate = TRUE, conf.int = TRUE))
nodes <- create_nodes(nodes = res_glm_tidy$term)
edges <- create_edges(from = res_glm_tidy$term, to = rep(as.character(res_glm$formula[[2]]),
nrow(nodes)), label=round(res_glm_tidy$estimate, 2))
graph <- create_graph(nodes_df = nodes, edges_df = edges)
render_graph(graph)
This famous (Fisher’s or Anderson’s) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.
## term estimate std.error statistic p.value conf.low
## 1 (Intercept) 1.8559975 0.25077711 7.400984 9.853855e-12 1.3603752
## 2 Sepal.Width 0.6508372 0.06664739 9.765380 1.199846e-17 0.5191189
## 3 Petal.Length 0.7091320 0.05671929 12.502483 7.656980e-25 0.5970350
## 4 Petal.Width -0.5564827 0.12754795 -4.362929 2.412876e-05 -0.8085615
## conf.high
## 1 2.3516197
## 2 0.7825554
## 3 0.8212289
## 4 -0.3044038
library ("broom")
library ("DiagrammeR")
lm_result<-lm(data=iris, Sepal.Length~Sepal.Width+Petal.Length+Petal.Width)
(lm_result_tidy<-tidy(lm_result,exponentiate = FALSE, conf.int = TRUE))
nodes <- create_nodes(nodes = lm_result_tidy$term)
edges <- create_edges(from = lm_result_tidy$term, to = rep(as.character(lm_result$terms[[2]]),
nrow(nodes)), label=round(lm_result_tidy$estimate, 2))
graph1 <- create_graph(nodes_df = nodes, edges_df = edges)
render_graph(graph1)
http://rich-iannone.github.io/DiagrammeR/mermaid.html
mermaid("
sequenceDiagram
customer->>ticket seller: ask ticket
ticket seller->>database: seats
alt tickets available
database->>ticket seller: ok
ticket seller->>customer: confirm
customer->>ticket seller: ok
ticket seller->>database: book a seat
ticket seller->>printer: print ticket
else sold out
database->>ticket seller: none left
ticket seller->>customer: sorry
end
")
mermaid("
sequenceDiagram
投稿者->>編集委員会: 論文投稿
編集委員会->>主査: 審査者決定依頼
主査->>審査者: 審査依頼
審査者->>主査: 審査報告
主査->>編集委員会: 審査報告
alt 掲載可
主査->>投稿者: accept通知
else 掲載不可
主査->>投稿者: reject通知
end
")