Create a gist now

Instantly share code, notes, and snippets.

RSiteCatalyst Sankey Diagram - Single Page to Multiple Pages
#### Authentication
SCAuth("key", "secret")
#### Get Pathing data: Single page, then ::anything:: pattern
pathpattern <- c("", "::anything::")
next_page <- QueuePathing("zwitchdev",
top = 50000)
#Optional step: Cleaning my pagename URLs to remove to domain for clarity
next_page$step.1 <- sub("","",
next_page$step.1, = TRUE)
next_page$step.2 <- sub("","",
next_page$step.2, = TRUE)
#Get unique values of page name to create nodes df
#Create an index value, starting at 0
nodes <-$step.1, next_page$step.2)))
names(nodes) <- "name"
nodes$nodevalue <- as.numeric(row.names(nodes)) - 1
#Convert string to numeric nodeid
links <- merge(next_page, nodes, by.x="step.1", by.y="name")
names(links) <- c("step.1", "step.2", "value", "source")
links <- merge(links, nodes, by.x="step.2", by.y="name")
names(links) <- c("step.1", "step.2", "value", "source", "target")
#Create next page Sankey chart
d3output = "C:/Users/rzwitc200/Desktop/sankey.html"
d3Sankey(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
fontsize = 12, nodeWidth = 100, file = d3output, width = 750, height = 600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment