I have written a UI, server and global.r for producing a network graph. It works well with one kind of layout (layout.fruchterman.reingold). I want a radio button for the listed layouts (radial, diagonal network and dendroNetwork):
Global.R file for producing the graph
### Social Network Analysis /Word Network ##########
###############################################################
tdm <- TermDocumentMatrix(r_stats_text_corpus,control = list(wordLenghts = c(1,Inf)))
idx <- which(dimnames(tdm)$Terms == "call") ##change the terms to be searched
tdm2 <- removeSparseTerms(tdm, sparse = 0.994)
m2 <- as.matrix(tdm2)
m2[m2>=1] <- 1
m2 <- m2 %*% t(m2) ##Adjaceny Matrix
g <- graph.adjacency(m2, weighted=T, mode = "undirected")
g <- simplify(g)
V(g)$label <- V(g)$name
V(g)$degree <- degree(g)
set.seed(3952)
layout1 <- layout.fruchterman.reingold(g)
###Different Formats for Social Network Graphics
##Radial
radial <- as.radialNetwork(fit)
radialNetwork(radial)
#Diagonal Network
diagonalNetwork(radial, height = NULL, width = NULL, fontSize = 10,fontFamily = "serif", linkColour = "#ccc", nodeColour = "#fff",nodeStroke = "steelblue", textColour = "#111", opacity = 0.9,margin = NULL)
#Dendro Network
dendroNetwork(fit, height = 500, width = 1000, fontSize = 10,
linkColour = "#ccc", nodeColour = "#fff", nodeStroke = "steelblue",
textColour = "#111", textOpacity = 0.9, textRotate = NULL,
opacity = 0.9, margins = NULL, linkType = c("elbow", "diagonal"),
treeOrientation = c("horizontal", "vertical"), zoom = TRUE)
Here is how my server.R looks for just the graph section
output$sna <- renderPlot({
plot(g, layout=layout1)
})
And the user interface ui.r is as below
conditionalPanel(condition="input.tabselected==10",radioButtons("layout","Select the layout to be plotted",c("layout.fruchterman.reingold","kawai","graph_net","radialNetwork","dendroNetwork","diagonal Network")))
How can I plot all the different formats? The same data is listed here (mostly unstructured comments from YouTube Comment Scraper):
head(data1,18) 1 "Call of star wars a halos destiny"
[2] "I thought of an new call of duty name CALL OF DUTY: The road of ARK GIANT"
[3] "Activision must be destroyed for the sake of video games. Boycott those pieces of shits."
[4] "FuturisticðŸ˜"
[5] "1:09 is that the XM 53"
[6] "Lets just not..."
[7] "Petition to call next CoD \"Space Cadets: Fanny Warfare\""
[8] "This is just pathetic...."
[9] "BLEAH"
[10] "I hate treyark now for the Campaign ending"
[11] "this isn't a cod trailer"
[12] "It's actually a good game just because you don't get to stand on solid ground 24/7 doesn't mean you have to cry about it, if you don't like the game then go play something else not rage about it to Activision, and do us a favor and go back to World at War please."
[13] "AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHahahahahahahahahahah! Oh, my God, I'm sorry sorry, I, it's just.... AHAHAHAHAHAHAHAHAHAHAHAHahahahah! Canada builds wall! AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH!!! REALLY!?!?! AHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH!" [14] "I like the last r seconds the best"
[15] "i love this game"
[16] "what jungle? lol"
[17] "Rated A for aMatures"
[18] "Phelps?"
I have to admit I find this a fascinating topic and a nice idea. You had most of the code together - with a very few changes I got it to work. Then I optimized a bit to reflect the input dependencies - i.e. added the
reactive
functions.Also I think you don't really want radio buttons here, what you really want are tabs. So I threw this together - adding a tab that can display them all together too:
Which when run yields various things including this:
And this: