[英]Trying to recreate a centrality graph from the qgraph R package
I am trying to recreate the graph that is provided by the function centralityPlot in qgraph.我正在尝试重新创建 function centralityPlot 在 qgraph 中提供的图表。 I got a dataframe that looks like this:
我得到一个 dataframe,看起来像这样:
symptom structure(list(symptom = c("9", "8", "7", "6", "5", "4", "3",
"2", "1"), lower_bound = c(0.209023862993771, -0.656057911395765,
-0.144732954079441, -0.240150983834066, -2.09690619987396, -1.14713000698362,
-1.78304406354482, -1.31269792892215, -1.04552934099257), mean = c(1.35359542511945,
0.546873106351184, 0.787717966105717, 0.42221064177518, -1.18693181743255,
-0.284265955202698, -1.19008711707311, -0.377827032555581, -0.0712852170875892
), upper_bound = c(1.9749871489344, 1.54642345677796, 1.46727206716789,
1.10712439281518, -0.0748008645128608, 0.812125575894532, -0.510038969136605,
0.587753574399307, 0.981045133733119)), class = "data.frame", row.names = c(NA,
-9L))
it should look like a singular plot like this one它应该看起来像一个单一的 plot 就像这个
It's supposed to be doable in GGplot but so far What I've gotten is a complete mess:它应该在 GGplot 中可行,但到目前为止我得到的是一团糟:
temporal.dep.in.plot <- ggplot(temporal.dep.in, aes(x = symptom)) +
ylim(NA, 2.25) +
geom_errorbar(
aes(ymin = lower_bound, ymax = upper_bound),
width = 0.4,
color = "#56B4E9"
) +
geom_segment(
aes(y = lower_bound, yend = upper_bound, xend = symptom),
linetype = "solid",
color = "#2166AC",
size = 6
) +
geom_point(
aes(y = mean),
shape = 16,
size = 9,
color = "#D6604D"
) +
theme_classic() +
coord_flip() +
ylab("Z-scores") + xlab("Symptoms") +
theme(axis.text.y = element_text(
face = "bold",
colour = c(
"#ff0000",
"#ffaa00",
"#aaff00",
"#00ff00",
"#00ffaa",
"#00aaff",
"#0000ff",
"#aa00ff",
"#ff00aa"
),
size = 14
))
which honestly only works trough sheer force of will.老实说,这只能通过纯粹的意志力起作用。
If that's too much, the main part that I'm trying to achieve right now is actually connecting the dots (mean) with a line, which so far has not been working with many methods that I've tried.如果这太多了,我现在尝试实现的主要部分实际上是将点(平均)与一条线连接起来,到目前为止,我还没有尝试过很多方法。
Not sure how your final plot should look like.不确定您的最终 plot 应该是什么样子。 As is it looks a quite different from the one in your image.
因为它看起来与您图片中的完全不同。 But to connect your mean points to could use a
geom_line
where the important step is to set group
aes to a constant value eg 1
.但是要将您的平均点连接到可以使用
geom_line
,其中重要的步骤是将group
aes 设置为常数值,例如1
。
library(ggplot2)
ggplot(temporal.dep.in, aes(x = symptom)) +
ylim(NA, 2.25) +
geom_errorbar(
aes(ymin = lower_bound, ymax = upper_bound),
width = 0.4,
color = "#56B4E9"
) +
geom_segment(
aes(y = lower_bound, yend = upper_bound, xend = symptom),
linetype = "solid",
color = "#2166AC",
size = 6
) +
geom_point(
aes(y = mean),
shape = 16,
size = 6,
color = "#D6604D"
) +
geom_line(aes(y = mean, group = 1), color = "#D6604D", size = 1) +
theme_classic() +
coord_flip() +
ylab("Z-scores") +
xlab("Symptoms") +
theme(axis.text.y = element_text(
face = "bold",
colour = c(
"#ff0000",
"#ffaa00",
"#aaff00",
"#00ff00",
"#00ffaa",
"#00aaff",
"#0000ff",
"#aa00ff",
"#ff00aa"
),
size = 14
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.