thomasp85 / ggraph

Grammar of Graph Graphics
https://ggraph.data-imaginist.com
Other
1.06k stars 111 forks source link

question on layout with clustering #242

Closed jwijffels closed 4 years ago

jwijffels commented 4 years ago

Hello,

I'm thinking about adding a plot.BTM function to my BTM package using ggraph. BTM is good for clustering text (https://cran.r-project.org/web/packages/BTM/index.html). In order to have a good layout, I would like to be able to group together similar nodes or similar edges such that they are plotted in the neighbourhood of one another.

Using the following code I basically generate the following graph but I would like to group nodes together in the graph based on the same best_topic. Do you have a suggestion what layout to use (or another algorithm from maybe the igraph package to make sure the nodes with the same best_topic are put close together on the graph.

many thanks!

library(igraph)
bi <- structure(list(term1 = c("classification", "regression", "model", 
                               "learn", "model", "descent", "linear", "dimensional", "mining", 
                               "network", "selection", "algorithm", "base", "forests", "forest", 
                               "algorithm", "package", "framework", "classification", "algorithm", 
                               "algorithm", "framework", "bayesian", "model", "analysis", "include", 
                               "data", "random", "implementation", "selection", "data", "data", 
                               "algorithm", "algorithm", "gradient", "data", "framework", "model", 
                               "cognitive", "cognitive", "microsoft", "high", "algorithm", "include", 
                               "fit", "interface", "partial", "log", "linear", "feed", "linear", 
                               "frequency", "allocation", "rest", "random", "forest", "base", 
                               "classification", "content", "corpora", "linear", "match", "data", 
                               "distribution", "distribution", "topic", "allocation", "language", 
                               "content", "file", "article", "convex", "fit", "group", "group", 
                               "author", "source", "function", "function", "function", "distance", 
                               "analysis", "model", "service", "article", "graph", "function", 
                               "data", "data", "data"), term2 = c("regression", "tree", "topic", 
                                                                  "machine", "regression", "gradient", "model", "high", "text", 
                                                                  "neural", "variable", "base", "model", "random", "random", "learn", 
                                                                  "provide", "text", "tree", "use", "descent", "mining", "tree", 
                                                                  "use", "data", "model", "use", "use", "random", "use", "dimensional", 
                                                                  "high", "machine", "gradient", "stochastic", "set", "provide", 
                                                                  "multinomial", "microsoft", "service", "service", "model", "method", 
                                                                  "method", "model", "package", "plot", "multinomial", "log", "neural", 
                                                                  "multinomial", "word", "latent", "service", "tree", "implementation", 
                                                                  "distance", "learn", "text", "source", "path", "string", "frequency", 
                                                                  "frequency", "word", "topic", "model", "model", "file", "text", 
                                                                  "corpora", "convex", "path", "lasso", "method", "title", "title", 
                                                                  "sparse", "version", "string", "string", "include", "word", "text", 
                                                                  "lexisnexis", "represent", "object", "data", "graph", "represent"
                               ), best_topic = c("10", "10", "12", "6", "10", "3", "1", "7", 
                                                 "13", "11", "7", "1", "10", "8", "8", "3", "13", "13", "10", 
                                                 "3", "3", "13", "10", "1", "1", "1", "1", "8", "8", "7", "7", 
                                                 "7", "6", "3", "3", "14", "13", "11", "9", "9", "9", "7", "6", 
                                                 "6", "4", "13", "12", "11", "11", "11", "11", "14", "12", "9", 
                                                 "8", "8", "6", "6", "5", "5", "4", "15", "14", "14", "14", "12", 
                                                 "12", "9", "5", "5", "5", "4", "4", "4", "4", "2", "2", "15", 
                                                 "15", "15", "15", "14", "12", "9", "5", "2", "15", "2", "2", 
                                                 "2"), cooc = c(38L, 27L, 22L, 21L, 19L, 18L, 18L, 17L, 15L, 15L, 
                                                                14L, 14L, 13L, 12L, 12L, 11L, 11L, 11L, 11L, 9L, 9L, 9L, 9L, 
                                                                9L, 8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 6L, 
                                                                6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 4L, 4L, 
                                                                4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 
                                                                3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 
                                                                1L, 1L, 1L), select = c(1L, 2L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 
                                                                                        2L, 2L, 4L, 1L, 2L, 2L, 2L, 3L, 5L, 3L, 4L, 4L, 6L, 3L, 4L, 5L, 
                                                                                        6L, 3L, 4L, 3L, 4L, 5L, 2L, 5L, 6L, 1L, 5L, 2L, 1L, 2L, 3L, 6L, 
                                                                                        3L, 4L, 1L, 6L, 2L, 3L, 4L, 5L, 6L, 2L, 3L, 4L, 5L, 6L, 5L, 6L, 
                                                                                        1L, 2L, 2L, 1L, 3L, 4L, 5L, 4L, 5L, 5L, 3L, 4L, 5L, 3L, 4L, 5L, 
                                                                                        6L, 1L, 2L, 2L, 3L, 4L, 5L, 6L, 6L, 6L, 6L, 3L, 6L, 4L, 5L, 6L
                                                                )), row.names = c(NA, -90L), class = "data.frame")
nodes <- structure(list(token = structure(c(1132L, 514L, 37L, 1098L, 884L, 
882L, 555L, 852L, 1424L, 1403L, 782L, 490L, 1443L, 190L, 1226L, 
50L, 1241L, 770L, 469L, 827L, 471L, 491L, 1080L, 1343L, 1485L, 
325L, 731L, 298L, 839L, 718L, 724L, 240L, 176L, 868L, 1020L, 
346L, 1162L, 479L, 597L, 507L, 756L, 100L, 725L, 1291L, 1242L, 
955L, 1340L, 365L, 257L, 1151L, 991L, 624L, 500L, 664L, 1475L, 
558L, 1414L, 1524L, 250L, 106L, 566L, 745L, 797L, 633L, 41L, 
977L, 85L, 1294L, 821L, 73L, 1496L, 913L, 361L), .Label = c("ability", 
"able", "absolute", "accelerate", "access", "accesse", "accord", 
"account", "accumulate", "achievable", "achieve", "active", "adaboost", 
"adadelta", "adagrad", "adam", "adapt", "adaptive", "add", "addition", 
"additional", "additions", "additive", "address", "adjust", "adopt", 
"advanced", "advantage", "afford", "agd", "aggregate", "agnostic", 
"aid", "aim", "alc", "alceste", "algorithm", "algorithmic", "alignment", 
"aline", "allocation", "allow", "alm", "alpha", "als", "alternative", 
"analy", "analyse", "analyses", "analysis", "analytic", "analyze", 
"analyzer", "andy", "angle", "answer", "api", "app", "appear", 
"applicable", "application", "apply", "approach", "approximate", 
"approximation", "apriori", "arbitrary", "architecture", "archive", 
"area", "argument", "array", "article", "artiere", "aspect", 
"assess", "associate", "association", "associations", "assort", 
"atom", "attain", "attribute", "austen", "author", "autoencoder", 
"automate", "automated", "automatic", "automl", "available", 
"average", "avoid", "back", "backend", "backward", "bag", "baoxun", 
"bart", "base", "based", "baseline", "basic", "batch", "baye", 
"bayesian", "belief", "benefit", "bennett", "bernoulli", "best", 
"beta", "biase", "big", "binary", "bindings", "bioinformatic", 
"birth", "biterm", "black", "blei", "block", "blockmodel", "boilerpipe", 
"boltzmann", "book", "boost", "boosting", "bootstrapping", "box", 
"brain", "break", "breiman", "bridge", "buhlmann", "build", "building", 
"bundle", "byte", "calculate", "calibrate", "call", "cambridge", 
"capability", "care", "carry", "cart", "case", "cat", "categorical", 
"categorization", "category", "causal", "caverphone", "celex", 
"censor", "censored", "certain", "cforest", "chain", "chall", 
"chapter", "character", "chart", "check", "checker", "chen", 
"cheng", "chernozhukov", "chipman", "choice", "choose", "chunking", 
"class", "classical", "classification", "classifier", "classify", 
"clean", "client", "clip", "cloud", "clouds", "cluster", "clustering", 
"cluto", "code", "coefficient", "coercing", "cognitive", "cohen", 
"coherent", "collapse", "collapsing", "collation", "collection", 
"color", "combination", "combine", "come", "command", "commander", 
"comment", "common", "communicate", "community", "companion", 
"company", "compare", "comparison", "compete", "compile", "component", 
"composite", "comprehensive", "comput", "computation", "computational", 
"compute", "computing", "concatenation", "concave", "concept", 
"conceptual", "condition", "conditional", "conduct", "conducting", 
"confidence", "configurable", "conger", "conll", "consist", "consistent", 
"constrain", "constraint", "construct", "constructive", "contain", 
"content", "contents", "context", "continuous", "contrast", "control", 
"convenient", "converge", "convergence", "convert", "convex", 
"coordinate", "copy", "corclust", "core", "coreference", "corelearn", 
"corpora", "corporaexplorerobject", "corpus", "correct", "correct.sign", 
"correction", "correlate", "correlation", "correspondence", "corresponding", 
"corrlda", "cosine", "cost", "count", "counting", "course", "covariance", 
"covariate", "cover", "coverage", "cox", "cpu", "cpus", "crammer", 
"create", "creature", "crfsuite", "criticism", "cross", "csv", 
"ctm", "ctree", "curve", "customer", "cutler", "cutoff", "cv.glmnet", 
"cyclical", "dale", "damerau", "danish", "data", "database", 
"dataset", "date", "david", "dbn", "deal", "death", "decision", 
"decomposition", "deep", "default", "define", "delevel", "delimiter", 
"demo", "dempster", "denoise", "density", "department", "depend", 
"dependence", "dependency", "dependent", "deploy", "derivative", 
"derive", "descent", "describe", "describing", "description", 
"design", "desirable", "desktop", "detail", "detect", "detection", 
"determine", "develop", "deviation", "device", "dgcmatrix", "diagnostic", 
"diagonal", "dictionary", "difference", "different", "dimension", 
"dimensional", "dimensionality", "direct", "directory", "dirichlet", 
"disagree", "discourse", "discover", "discovery", "discrete", 
"discretization", "discriminant", "dispatch", "display", "dissimilarity", 
"distance", "distances", "distribute", "distributed", "distribution", 
"distributions", "diversity", "divide", "dkm", "document", "documentation", 
"domain", "dow", "download", "dplyr", "draw", "drive", "dutch", 
"dynamic", "earlier", "easy", "eclat", "econometric", "edge", 
"edit", "effect", "efficiency", "efficient", "elastic", "element", 
"elimination", "emb", "embed", "embedding", "employ", "enable", 
"encod", "encoding", "endpoint", "engine", "engineers", "english", 
"enhancement", "enjoy", "ensemble", "entire", "entity", "environment", 
"error", "essential", "estimate", "estimation", "estimator", 
"europresse", "evaluate", "evaluation", "event", "evidence", 
"evidential", "evolutionary", "evtree", "examining", "example", 
"exclusivity", "execution", "exemplify", "exercise", "exist", 
"expand", "expect", "expectation", "experimental", "expert", 
"explain", "explainprediction", "exploit", "exploration", "explore", 
"exploring", "exponential", "export", "expose", "express", "expression", 
"extend", "extensible", "extension", "extensive", "extent", "extract", 
"extracting", "extraction", "extractor", "extreme", "facilitate", 
"facilitatory", "facility", "factiva", "factor", "false", "family", 
"famious", "famous", "fan", "fashion", "fast", "faster", "feature", 
"feed", "field", "file", "files", "filter", "find", "finite", 
"finnish", "first", "fisher", "fit", "fitting", "fix", "fleiss", 
"flesch", "flexibility", "flexible", "flow", "focus", "follow", 
"forecast", "forest", "forests", "form", "format", "formatting", 
"formula", "forward", "fourier", "fractions", "frame", "framework", 
"frb", "frbs", "frbspmml", "frbss", "free", "french", "frequency", 
"frequent", "freund", "friedman", "friendly", "frst", "full", 
"function", "functional", "functionality", "furthermore", "fuse", 
"fused", "fuzzy", "gain", "gamlss", "gap", "gaussian", "gear", 
"genabel", "genentic", "general", "generalisation", "generalize", 
"generalized", "generate", "generation", "generic", "genetic", 
"genomics", "gentle", "geographical", "george", "german", "get", 
"ggplot", "gibb", "gigabyte", "gini", "give", "glm", "glmnet", 
"global", "glove", "gnome", "google", "gps", "gpus", "gradient", 
"graham", "gram", "graph", "graphic", "graphical", "graphing", 
"greedy", "greg", "grf", "grounded", "group", "grouped", "grouping", 
"growth", "gruen", "gsub", "gsubfn", "guestrin", "guo", "gutenberg", 
"guus", "gwaa.data", "gwet", "hahsler", "hallmark", "ham", "handle", 
"handling", "hansen", "hash", "hazard", "header", "helper", "helpful", 
"hessian", "heteroscedastic", "heuristic", "hidden", "hierarchical", 
"hierarchy", "hieu", "high", "higher", "highlight", "hinge", 
"holte", "homogeneity", "hornik", "hothorn", "html", "huang", 
"huberize", "human", "hungarian", "hunspell", "hybridization", 
"hyphenation", "ice", "icu", "idea", "identification", "identifier", 
"identify", "idf", "ill", "illustration", "imbalanced", "implement", 
"implementation", "import", "importance", "important", "impose", 
"imprecise", "improve", "improvement", "impurity", "include", 
"incorporate", "independence", "independent", "index", "indexing", 
"indirect", "indiscernibility", "individual", "induction", "industry", 
"inference", "infinitesimal", "information", "infrastructure", 
"initialization", "input", "insensitive", "instability", "installation", 
"instance", "instrumental", "integer", "integrate", "integrated", 
"integration", "intelligence", "intensive", "intent", "interaction", 
"interest", "interface", "interfase", "international", "interpolation", 
"interval", "intraclass", "introduce", "introduction", "intuitive", 
"inverse", "involve", "isbn", "ishwaran", "isotropic", "italian", 
"itemset", "itemsets", "iterative", "jaccard", "jam", "janeaustenr", 
"jar", "jasa", "java", "jawbone", "jiafeng", "jmlr", "joint", 
"jone", "joshua", "journal", "json", "jump", "kano", "kappa", 
"kea", "kernel", "kernlab", "key", "keyphrase", "keyword", "kind", 
"kmode", "knn", "know", "kogalur", "kondrak", "kosorok", "krippendorff", 
"lab", "labelling", "laboratory", "lambdamart", "lan", "language", 
"lansing", "laptop", "lar", "large", "larger", "lasso", "latent", 
"latex", "latter", "law", "layer", "lda", "learn", "learner", 
"learning", "least", "leave", "left", "leipzig", "lemmatization", 
"length", "less", "level", "levenshtein", "leverage", "lexical", 
"lexisnexis", "liaw", "liblinear", "library", "libstemmer", "life", 
"lift", "likelihood", "limit", "limiting", "line", "linear", 
"linguistic", "linguists", "link", "list", "literature", "lix", 
"llm", "load", "loading", "local", "locale", "locality", "location", 
"log", "logge", "logistic", "longer", "longitudinal", "look", 
"loss", "lot", "low", "lsa", "lssvm", "ltrc", "machine", "macro", 
"mail", "main", "make", "management", "manipulate", "many", "map", 
"mapping", "maptpx", "marginal", "markup", "mars", "mass", "match", 
"matching", "mathematical", "matrice", "matrix", "maximize", 
"maximum", "mbgd", "mcculloch", "mcmc", "mcp", "mdl", "mean", 
"measure", "measurement", "mechanism", "meinshausen", "membership", 
"memetic", "memory", "message", "meta", "metadata", "metaphone", 
"method", "methods", "metic", "metric", "mgd", "microarray", 
"microsoft", "mihalcea", "mind", "mine", "miner", "minhash", 
"mini", "minimalist", "minimax", "minimization", "minimize", 
"minimum", "mining", "mis", "misc", "miscellaneous", "miss", 
"missing", "mix", "mixed", "mixture", "mlr", "mob", "mobile", 
"mode", "model", "modeling", "modelling", "models", "modern", 
"mohammadi", "moment", "momentum", "monkeylearn", "morphological", 
"mparheuristic", "mse", "mtld", "multicollinear", "multicore", 
"multidimensional", "multinomial", "multiple", "multithread", 
"multivariate", "naive", "nam", "name", "native", "natural", 
"ncvreg", "nearest", "need", "neighbor", "net", "network", "networnks", 
"neural", "neuro", "new", "news", "newspaper", "next", "ngram", 
"nice", "nlp", "nma", "node", "noisy", "nominal", "non", "nonconvex", 
"nonlinear", "nonparametric", "nonstationary", "normal", "normalization", 
"norquest", "norwegian", "note", "novel", "novelty", "number", 
"numeric", "numerical", "nysiis", "object", "objective", "obscure", 
"observation", "observed", "obtain", "occur", "occurrence", "ocr", 
"odbc", "offer", "one", "oner", "onigmo", "open", "openmp", "opennlp", 
"operation", "optical", "optim", "optimal", "optimization", "optimize", 
"optimizer", "optimizing", "optimum", "option", "optional", "opus", 
"order", "ordeval", "ordinal", "ordinary", "organization", "oriented", 
"original", "outcome", "output", "overcome", "overfitting", "overlapping", 
"owe", "package", "page", "pagerank", "pair", "pairwise", "pam", 
"panel", "paper", "papers", "paragraph", "parallel", "parallelizable", 
"parallelization", "parallelize", "parameter", "parameterization", 
"parameterize", "parametic", "parametric", "parse", "parsing", 
"part", "partial", "particular", "partimat", "partition", "partitione", 
"partitioning", "partner", "party", "partykit", "partytion", 
"partytioning", "passage", "past", "paste", "path", "paths", 
"pathwise", "pattern", "patterns", "paul", "pawlak", "pca", "pcan", 
"penalise", "penalize", "penaltie", "penalty", "penaly", "penn", 
"per", "perform", "performance", "perl", "permute", "phan", "phd", 
"phonetic", "php", "phrase", "picasso", "place", "platform", 
"plet", "plot", "plots", "plott", "plotting", "plug", "pluggable", 
"pmml", "point", "poisson", "polysemy", "popular", "population", 
"portable", "porter", "portuguese", "position", "positivity", 
"possibility", "possible", "post", "posterior", "power", "powerful", 
"practical", "precision", "predict", "prediction", "predictive", 
"predictor", "prepare", "preprocesse", "preprocessing", "preselection", 
"presence", "present", "press", "previous", "principal", "print", 
"printing", "prior", "probabilistic", "probability", "problem", 
"procedure", "process", "processing", "produce", "productive", 
"program", "programmer", "programming", "project", "projection", 
"proper", "property", "proportional", "proposal", "propose", 
"proteomics", "provide", "provider", "prun", "public", "publish", 
"purpose", "python", "qdap", "qgram", "qiang", "qualitative", 
"quantile", "quantitative", "quasi", "query", "quinlan", "rada", 
"ram", "random", "randomforest", "randomforestsrc", "range", 
"rank", "ranking", "rate", "ratio", "rattle", "raw", "rbm", "rcpp", 
"rde", "reachable", "read", "readability", "reading", "real", 
"reasonable", "reasoning", "recall", "recent", "recognition", 
"recommend", "recursive", "reduce", "reduction", "redundant", 
"refer", "reference", "refine", "regex", "region", "register", 
"regression", "regular", "regularization", "regularize", "reimplementation", 
"reinforcement", "relate", "related", "relation", "relationship", 
"relaxation", "relaxed", "relevant", "reliability", "relief", 
"removal", "replace", "replacement", "repository", "represent", 
"representation", "representing", "require", "resampl", "resampling", 
"research", "researchers", "residual", "resolution", "response", 
"rest", "restrict", "result", "retrieval", "retrieve", "return", 
"reuse", "rgtk", "ridge", "ridgeway", "risk", "rmsprop", "robert", 
"robotic", "robust", "roc", "rocr", "romanian", "root", "rough", 
"routine", "routines", "royal", "rpart", "rsf", "rsnn", "rss", 
"rst", "ruby", "rule", "rules", "run", "russian", "rweka", "rwekajar", 
"sag", "sample", "sampler", "sampling", "sarah", "sarahplus", 
"satisfaction", "save", "scad", "scalability", "scalable", "scale", 
"scatter", "schapire", "science", "scientist", "score", "scoring", 
"scott", "scree", "screen", "screening", "script", "seamless", 
"search", "searching", "see", "segmentation", "select", "selection", 
"self", "semantic", "semiparametric", "sensitive", "sensitivity", 
"sentence", "sentenx", "sentiment", "separable", "separate", 
"sequence", "sequential", "series", "server", "service", "set", 
"setting", "several", "sgd", "shadows", "shafer", "shape", "shardsplot", 
"share", "shingle", "shingled", "shiny", "shoot", "short", "shortest", 
"show", "shrinkage", "sidebar", "sigil", "sign", "similar", "similarity", 
"similarly", "simple", "simulate", "simulator", "singer", "single", 
"singular", "sis", "site", "skip", "sknn", "slab", "slda", "slice", 
"small", "smith", "smog", "snn", "society", "software", "solution", 
"solve", "solver", "sophisticat", "sophisticated", "sotu", "soundex", 
"source", "space", "spanish", "sparse", "sparser", "special", 
"specific", "specificity", "specify", "spectral", "spectrum", 
"spee", "speech", "speed", "spell", "spelling", "spherical", 
"spike", "spindler", "spline", "split", "splits", "spreadsheet", 
"sql", "square", "squares", "src", "ssgd", "stability", "stack", 
"stage", "stagewise", "standalone", "standard", "starr", "starspace", 
"start", "state", "stationary", "statistic", "statistical", "stein", 
"stem", "stemmer", "step", "stepclass", "stepwise", "sting", 
"stm", "stochastic", "stone", "streaming", "string", "stringi", 
"strong", "structural", "structure", "study", "stuttgart", "style", 
"subject", "subsampling", "subspace", "substitution", "sufficient", 
"suggest", "suitable", "suite", "summarization", "summarize", 
"summary", "super", "superior", "supervise", "supervised", "supervisor", 
"support", "sure", "surface", "survey", "survival", "svm", "svmlight", 
"svrg", "swedish", "syllable", "synonym", "system", "tabenefit", 
"table", "tabular", "taddy", "tagging", "take", "talk", "tanalysis", 
"tarau", "target", "task", "tasnks", "team", "technique", "tell", 
"template", "tensor", "tensorflow", "term", "termination", "terminology", 
"terms", "tesseract", "test", "text", "textir", "textrank", "texts", 
"textual", "tgp", "theories", "theory", "tibshirani", "tidy", 
"time", "title", "tm.plugin.webmining", "token", "tokenization", 
"tokenizer", "tool", "toolbox", "toolkit", "tools", "top", "topic", 
"topicmodel", "topology", "total", "trace", "track", "trade", 
"trademark", "traditional", "train", "training", "transaction", 
"transcript", "transcripts", "transform", "transformation", "translating", 
"transliteration", "treatment", "tree", "treebank", "treetagger", 
"truncate", "truncated", "tune", "tuning", "turkish", "turn", 
"tutorial", "tweet", "twitter", "type", "udpipe", "ultrahigh", 
"unbalanced", "undertake", "undirected", "unequal", "unicode", 
"unified", "uniformly", "union", "unique", "universal", "university", 
"unstable", "unsupervise", "unsupervised", "updating", "url", 
"usage", "use", "useful", "user", "utility", "utilize", "vagueness", 
"valid", "validation", "value", "variability", "variable", "variance", 
"variant", "variation", "variety", "various", "varying", "vcluster", 
"vec", "vector", "vectorization", "version", "vignette", "visualization", 
"visualize", "vocabulary", "vocd", "von", "wang", "warehousing", 
"warm", "warranty", "waterman", "way", "web", "website", "weight", 
"weighted", "weighting", "weka", "wide", "wien", "william", "window", 
"wing", "winkler", "wise", "wit", "witten", "word", "wordnet", 
"work", "wrap", "wrapper", "write", "writing", "wrong", "xgboost", 
"xml", "xuan", "xyplot", "yan", "yanyan", "yield", "yielding", 
"youtokentome", "yunm", "zadeh", "zdzislaw", "zeileis", "zeng", 
"zhexue", "zipf"), class = "factor"), topic = c(10L, 15L, 3L, 
8L, 11L, 11L, 3L, 12L, 12L, 13L, 6L, 8L, 10L, 9L, 7L, 14L, 9L, 
11L, 11L, 9L, 5L, 8L, 13L, 15L, 7L, 3L, 6L, 14L, 13L, 9L, 4L, 
5L, 10L, 11L, 12L, 7L, 9L, 4L, 7L, 14L, 11L, 6L, 12L, 2L, 14L, 
13L, 3L, 14L, 5L, 2L, 4L, 8L, 13L, 13L, 8L, 2L, 2L, 14L, 4L, 
10L, 4L, 5L, 15L, 14L, 12L, 12L, 2L, 15L, 6L, 5L, 15L, 15L, 15L
), probability = c(0.161647484859206, 0.143018420606996, 0.13695649773046, 
0.132900321369005, 0.125190877913235, 0.122687561018349, 0.102720134294897, 
0.101477476475739, 0.0959178284014622, 0.0932833052455298, 0.0932113511950036, 
0.0908647131408735, 0.0783991342171533, 0.0783211141955537, 0.0765527416331104, 
0.0742988492858845, 0.0735758179704368, 0.0701179062257491, 0.0676145893308634, 
0.0664578736327615, 0.0652919811873399, 0.0651009532591156, 0.0646655431545253, 
0.063992323179107, 0.0621318513095278, 0.0618573779363204, 0.057859384875786, 
0.0574796417508795, 0.0561862062386721, 0.0545946330699694, 0.0538368380491027, 
0.05357591176126, 0.052730892769187, 0.052594687961549, 0.051440643807247, 
0.0510388587529258, 0.0498493368448525, 0.0477204056417972, 0.0477109609859452, 
0.0476684373554599, 0.0475880541717776, 0.0471466678093565, 0.0458809957329701, 
0.0455515406720346, 0.0448652360996258, 0.0413473666359291, 0.0397694015262792, 
0.0392588335879574, 0.0385123939277286, 0.03701596153299, 0.0367108273086474, 
0.0366252186529622, 0.0360477810635208, 0.0360477810635208, 0.0352692312907644, 
0.0341707684866418, 0.0341707684866418, 0.0336524310762891, 0.0330409678642641, 
0.0326125413640242, 0.0305943949013419, 0.0301437729091, 0.0301239957100119, 
0.0294476291925379, 0.0292020515101394, 0.0292020515101394, 0.0284803823939454, 
0.0282424219617288, 0.0278637770897833, 0.0267963245016486, 0.0207161269685965, 
0.0188345532203135, 0.0169529794720304)), row.names = c(NA, -73L
), class = "data.frame")
g <- graph_from_data_frame(bi, vertices = nodes)
library(ggraph)
library(igraph)
library(ggplot2)
g %>% 
  ggraph(layout = "igraph", algorithm = "fr") +
  geom_edge_link0(aes(edge_alpha = cooc, edge_width = cooc, edge_colour = best_topic)) +
  geom_node_point(aes(colour = topic, size = probability)) +
  geom_node_text(aes(label = name), vjust = 1.8, col = "darkgreen") +
  ggtitle("BTM clusters") +
  theme_void()

Rplot01

jwijffels commented 4 years ago

Never mind. Found a way to solve this.