尝试从qgraph R包重新创建中心图

ssgvzors  于 2023-02-06  发布在  其他
关注(0)|答案(1)|浏览(218)

我尝试重新创建由qgraph中的centralityPlot函数提供的图形,得到了一个如下所示的 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))

它应该看起来像这样一个单一图

这应该是可行的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
  ))

老实说,这只能通过纯粹的意志力来实现
如果这太多了,我现在要做的主要工作是用一条线把点(平均值)连接起来,到目前为止,我尝试过的很多方法都不起作用。

e0bqpujr

e0bqpujr1#

不确定你的最终图应该是什么样子。它看起来和你的图像有很大的不同。但是要把你的平均点连接到,可以使用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
  ))

相关问题