Skip to content

Instantly share code, notes, and snippets.

@jalapic
Last active Aug 29, 2015
Embed
What would you like to do?
library(DiagrammeR)
#import onetrain data
head(onetrain)
edges <- onetrain
edges #edges.minlen doesn't seem to do much in final viz
# Create a 'nodes' data frame
mynodes <- unique(c(as.character(edges[,1]), as.character(edges[,2])))
nodes <- data.frame(nodes=mynodes,
style = rep("filled", length(mynodes)),
fillcolor = c(rep("red", 37), rep("yellow", 2), "red",
rep("orange", 2), "purple", "gray55", "orange", rep("blue", 2), "red",
rep("blue", 2))
)
nodes$fontcolor <- c(rep("white", 37), rep("black", 2), rep("white", 11))
# Create the graph
### tried using graph paramaters 'mindist' and 'nodesep' to try and minimize
### the overlap between nodes (e.g. Times Square and its neighbors)
### but with 'overlap=true' they seem irrelevant
### making overlap=false leads to a linear graph that doesn't look that good (imo)
grViz("
graph two_df {
# Graph statements
graph [layout = neato, overlap = true]
# Node statements
node [shape = circle, fontsize = 15, width = .9, fixedsize = true]
# Substitution with 'graphviz_nodes_edges_df' function
@@1
}
[1]: graphviz_nodes_edges_df(nodes_df = nodes, edges_df = edges, directed = FALSE)
")
### Data
"edge_from","edge_to","minlen","color"
"1","VCP242","238",0.3,"red"
"2","238","231",0.3,"red"
"3","231","225",0.3,"red"
"4","225","215",0.3,"red"
"5","215","207",0.3,"red"
"6","207","Dyckman",0.3,"red"
"7","Dyckman","191",0.3,"red"
"8","191","181",0.3,"red"
"9","181","168",0.3,"red"
"10","168","157",0.3,"red"
"11","157","145",0.3,"red"
"12","145","137",0.3,"red"
"13","137","125",0.3,"red"
"14","125","116",0.3,"red"
"15","116","110",0.3,"red"
"16","110","103",0.3,"red"
"17","103","96",0.3,"red"
"18","96","86",0.3,"red"
"19","86","79",0.3,"red"
"20","79","72",0.3,"red"
"21","72","66",0.3,"red"
"22","66","59",0.3,"red"
"23","59","50",0.3,"red"
"24","50","TimesSq",0.3,"red"
"25","TimesSq","Penn",0.3,"red"
"26","Penn","28",0.3,"red"
"27","28","23",0.3,"red"
"28","23","18",0.3,"red"
"29","18","14",0.3,"red"
"30","14","Christopher",0.3,"red"
"31","Christopher","Houston",0.3,"red"
"32","Houston","Canal",0.3,"red"
"33","Canal","Franklin",0.3,"red"
"34","Franklin","Chambers",0.3,"red"
"35","Chambers","Rector",0.3,"red"
"36","Rector","SouthFerry",0.3,"red"
"37","SouthFerry","CourtSt",0.7,"yellow"
"38","SouthFerry","RectorSt",0.7,"yellow"
"39","Chambers","ParkPl",0.7,"black"
"40","14","Chambers",0.7,"black"
"41","Penn","14",0.7,"black"
"42","TimesSq","34",0.7,"yellow"
"43","TimesSq","49",0.7,"yellow"
"44","TimesSq","5thav",0.7,"purple"
"45","TimesSq","GrandC",0.7,"gray55"
"46","59","7thav",0.7,"orange"
"47","59","TimesSq",0.7,"black"
"48","59","72bc",0.7,"blue"
"49","59","50ce",0.7,"blue"
"50","72","59",0.7,"black"
"51","96","72",0.7,"black"
"52","96","125",0.7,"black"
"53","96","CPN110",0.7,"red"
"54","168","175",0.7,"blue"
"55","168","163",0.7,"blue"
@jalapic

This comment has been minimized.

Copy link
Owner Author

@jalapic jalapic commented Feb 21, 2015

The resulting graph looks ok, it's actually very good to visualize the express stops south of Penn - but I'd like to find ways to pull apart some of the more clustered nodes (e.g. Times Sq) without making the diagram becoming chaotic and very zig-zaggy.

@rich-iannone

This comment has been minimized.

Copy link

@rich-iannone rich-iannone commented Feb 21, 2015

Looks great! I have some ideas/suggestions:

  • use fontname = Helvetica for that MTA signage look
  • try using ports if you need to orient nodes... You can specify which Cardinal direction edges emit from and connect to
  • millennia should provide some necessary spacing; I wonder why it doesn't here. I'll look I to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment