plot_network {PsychWordVec} | R Documentation |
Visualize a (partial correlation) network graph of words.
Description
Visualize a (partial correlation) network graph of words.
Usage
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,
...
)
Arguments
data |
A |
words |
[Option 1] Character string(s). |
pattern |
[Option 2] Regular expression (see |
index |
Use which index to perform network analysis?
Can be |
alpha |
Significance level to be used for not showing edges. Defaults to |
bonf |
Bonferroni correction of p value. Defaults to |
max |
Maximum value for scaling edge widths and colors. Defaults to the highest value of the index.
Can be |
node.size |
Node size. Defaults to 8*exp(-nNodes/80)+1. |
node.group |
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 |
Node color(s). Can be a character vector of colors corresponding to |
label.text |
Node label of text. Defaults to original words. |
label.size |
Node label font size. Defaults to |
label.size.equal |
Make the font size of all labels equal. Defaults to |
label.color |
Node label color. Defaults to |
edge.color |
Edge colors for positive and negative values, respectively.
Defaults to |
edge.label |
Edge label of values. Defaults to |
edge.label.size |
Edge label font size. Defaults to |
edge.label.color |
Edge label color. Defaults to |
edge.label.bg |
Edge label background color. Defaults to |
file |
File name to be saved, should be png or pdf. |
width , height |
Width and height (in inches) for the saved file.
Defaults to |
dpi |
Dots per inch. Defaults to |
... |
Other parameters passed to |
Value
Invisibly return a qgraph
object,
which further can be plotted using plot()
.
Download
Download pre-trained word vectors data (.RData
):
https://psychbruce.github.io/WordVector_RData.pdf
See Also
Examples
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"))