
Visualize a (partial correlation) network graph of words.
plot_network(
data,
words = NULL,
pattern = NULL,
index = c("pcor", "cor", "glasso", "sim"),
alpha = 0.05,
bonf = FALSE,
max = NULL,
node.size = "auto",
node.group = NULL,
node.color = NULL,
label.text = NULL,
label.size = 1.2,
label.size.equal = TRUE,
label.color = "black",
edge.color = c("#009900", "#BF0000"),
edge.label = FALSE,
edge.label.size = 1,
edge.label.color = NULL,
edge.label.bg = "white",
file = NULL,
width = 10,
height = 6,
dpi = 500,
...
)
Invisibly return a qgraph
object,
which further can be plotted using plot()
.
A wordvec
(data.table) or
embed
(matrix),
see data_wordvec_load
.
[Option 1] Character string(s).
[Option 2] Regular expression (see str_subset
).
If neither words
nor pattern
are specified (i.e., both are NULL
),
then all words in the data will be extracted.
Use which index to perform network analysis?
Can be "pcor"
(partial correlation, default and suggested),
"cor"
(raw correlation),
"glasso"
(graphical lasso-estimation of partial correlation matrix
using the glasso
package),
or "sim"
(pairwise cosine similarity).
Significance level to be used for not showing edges. Defaults to 0.05
.
Bonferroni correction of p value. Defaults to FALSE
.
Maximum value for scaling edge widths and colors. Defaults to the highest value of the index.
Can be 1
if you want to compare several graphs.
Node size. Defaults to 8*exp(-nNodes/80)+1.
Node group(s). Can be a named list (see examples) in which each element is a vector of integers identifying the numbers of the nodes that belong together, or a factor.
Node color(s). Can be a character vector of colors corresponding to node.group
.
Defaults to white (if node.group
is not specified)
or the palette of ggplot2 (if node.group
is specified).
Node label of text. Defaults to original words.
Node label font size. Defaults to 1.2
.
Make the font size of all labels equal. Defaults to TRUE
.
Node label color. Defaults to "black"
.
Edge colors for positive and negative values, respectively.
Defaults to c("#009900", "#BF0000")
.
Edge label of values. Defaults to FALSE
.
Edge label font size. Defaults to 1
.
Edge label color. Defaults to edge.color
.
Edge label background color. Defaults to "white"
.
File name to be saved, should be png or pdf.
Width and height (in inches) for the saved file.
Defaults to 10
and 6
.
Dots per inch. Defaults to 500
(i.e., file resolution: 4000 * 3000).
Other parameters passed to qgraph
.
Download pre-trained word vectors data (.RData
):
https://psychbruce.github.io/WordVector_RData.pdf
plot_similarity
plot_wordvec_tSNE
d = as_embed(demodata, normalize=TRUE)
words = cc("
man, woman,
he, she,
boy, girl,
father, mother,
mom, dad,
China, Japan
")
plot_network(d, words)
p = plot_network(
d, words,
node.group=list(Gender=1:6, Family=7:10, Country=11:12),
node.color=c("antiquewhite", "lightsalmon", "lightblue"),
file="network.png")
plot(p)
unlink("network.png") # delete file for code check
# network analysis with centrality plot (see `qgraph` package)
qgraph::centralityPlot(p, include="all", scale="raw",
orderBy="Strength")
# graphical lasso-estimation of partial correlation matrix
plot_network(
d, words,
index="glasso",
# threshold=TRUE,
node.group=list(Gender=1:6, Family=7:10, Country=11:12),
node.color=c("antiquewhite", "lightsalmon", "lightblue"))
Run the code above in your browser using DataLab