Skip to content

Instantly share code, notes, and snippets.

@Sandy4321
Forked from abresler/summarySequenceDiagram
Created December 17, 2015 16:13
Show Gist options
  • Save Sandy4321/ecfc65f858d40181f801 to your computer and use it in GitHub Desktop.
Save Sandy4321/ecfc65f858d40181f801 to your computer and use it in GitHub Desktop.
Quick Little Sequence Diagram for Any R Data-frame
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