-
-
Save Sandy4321/ecfc65f858d40181f801 to your computer and use it in GitHub Desktop.
Quick Little Sequence Diagram for Any R Data-frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summarySequenceDiagram <- function(df = mtcars, column_fill = "#05ffff", stroke_fill = "#0D3FF3", stroke_width = 1, inBrowser = TRUE){ | |
library(DiagrammeR) | |
library(dplyr) | |
if(inBrowser == T){ | |
options(viewer = NULL) | |
} | |
connections <- sapply( | |
1:ncol(df) | |
, function(i){ | |
paste0( | |
i | |
, "(", colnames(df)[i], ")---" | |
, i, "-stats(" | |
, paste0( | |
df[,i] %>% summary %>% names | |
, ": " | |
, df[,i] %>% summary %>% unname | |
, collapse="<br/>" | |
) | |
, ")" | |
) | |
} | |
) | |
paste0(", stroke-width:",stroke_width,"px;") -> sw | |
paste0("classDef column fill:", | |
column_fill,", stroke:",stroke_fill, sw) -> color_options | |
diagram <- | |
paste0( | |
"graph TD;", "\n", | |
paste(connections, collapse = "\n"), "\n", | |
color_options ,"\n", | |
"class ", paste0(1:length(connections), collapse = ","), " column; | |
") | |
DiagrammeR(diagram) | |
} | |
#base example summarySequenceDiagram() | |
#iris example summarySequenceDiagram(iris) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment