(freq.terms <- findFreqTerms(dtm, lowfreq = 30))
agraph <- graphplot(dtm,term = freq.terms,corThreshold = 0.1)
write.graph(agraph,"e:/agraphsiria.graphml", format=c("graphml"))
Showing posts with label textmining. Show all posts
Showing posts with label textmining. Show all posts
Thursday, April 21, 2016
Alternate plot function for tm with Igraph support.
graphplot <-
function(x,
terms = sample(Terms(x), 20),
corThreshold = 0.7,
weighted=TRUE,
diag=FALSE,
...)
{
if (system.file(package = "igraph") == "")
stop("Plotting requires package 'igraph'.")
m <- if (inherits(x, "TermDocumentMatrix")) t(x) else x
m <- as.matrix(m[, terms])
c <- cor(m)
c[c < corThreshold] <- 0
c[is.na(c)] <- 0
diag(c) <- 0
tmgraph <- graph.adjacency(c, mode=c("undirected"), weighted=TRUE, diag=FALSE,
add.colnames=NULL, add.rownames=NA)
plot(tmgraph)
invisible(tmgraph)
}
example usage:
graphplot(dtm,term = freq.terms,corThreshold = 0.5)
dtm- document term matrix
terms- similar to plot.tm
threshold-similar with plot.pm
for saving/export:
agraph <- graphplot(dtm,term = freq.terms,corThreshold = 0.3)
write.graph(agraph,"e:/agraph.graphml", format=c("graphml"))
function(x,
terms = sample(Terms(x), 20),
corThreshold = 0.7,
weighted=TRUE,
diag=FALSE,
...)
{
if (system.file(package = "igraph") == "")
stop("Plotting requires package 'igraph'.")
m <- if (inherits(x, "TermDocumentMatrix")) t(x) else x
m <- as.matrix(m[, terms])
c <- cor(m)
c[c < corThreshold] <- 0
c[is.na(c)] <- 0
diag(c) <- 0
tmgraph <- graph.adjacency(c, mode=c("undirected"), weighted=TRUE, diag=FALSE,
add.colnames=NULL, add.rownames=NA)
plot(tmgraph)
invisible(tmgraph)
}
example usage:
graphplot(dtm,term = freq.terms,corThreshold = 0.5)
dtm- document term matrix
terms- similar to plot.tm
threshold-similar with plot.pm
for saving/export:
agraph <- graphplot(dtm,term = freq.terms,corThreshold = 0.3)
write.graph(agraph,"e:/agraph.graphml", format=c("graphml"))
Subscribe to:
Posts (Atom)

