ggplot:R 代码,用于为按值分面的多级模拟数据制作箱线图和线图

ggplot: R code to make box plot and line plots for multiple level simulation data faceted by values

我需要帮助来使用这些数据绘制图表,我对使用 R 还很陌生,但我知道我可以用它来绘制图表。 如果这个特定问题得到了回答,我对此感到抱歉。我可能不知道到底要搜索什么,因为我已经在这里搜索了好几天,但没有得到我想要的。 数据是networkx图的模拟。这是生成数据的多级循环。 我必须考虑因素 "scf" 和 "ran"。然后对于其中的每一个,我的大小都在 500 到 15,000 之间。对于每种尺寸,我有 1%、2%、3%、5%、7% 和 10% 的百分比。对于这些百分比中的每一个,迭代运行 10 次,从 0 到 9。 我还有 2 个因素显示此数据在(post)操作之前(之前)和之后(post)。

我想达到的目标包括 1 个直径的箱线图,每个测量百分比的前值和 post 值并排显示,按尺寸分面 numE 的 pre 和 post 值的 2 个线图都在一个按大小分面的图上 每组尺寸的 percentP 分别刻面的 pre 和 post 密度值的 3 个线图。

因为我是 R 的新手,所以我尝试了不同的方法但没有得到我的输出。

  ggplot(simulation3_mod_500, aes(x = simulation3_mod_500$percentP,     y=simulation3_mod_500$density, group=simulation3_mod_500$node_percent, col=simulation3_mod_500$status)) + 
  geom_line() + 
  xlab('Percent') +
  ylab('Density')  

还有这个……

ggplot(data = simulation3_mod, mapping = aes(x = simulation3_mod$percentP, y = simulation3_mod$density, color = simulation3_mod$status)) +
  geom_line() +
  facet_wrap(~ simulation3_mod_500$density)

还有这个……

ggplot(simulation3_mod_500, aes(x=simulation3_mod_500$percentP , y=simulation3_mod_500$density, fill=simulation3_mod_500$status)) +
  geom_boxplot() + 
  facet_wrap(~ simulation3_mod_500$percentP)  

这是我的部分数据,注意这是 500 码,还有其他尺码

simulation3_mod_500 <-
  data.frame(
    stringsAsFactors = FALSE,
    percentP = c(
      "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%",
      "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%", "1%",
      "2%", "2%", "2%", "2%", "2%", "2%", "2%", "2%", "2%", "2%", "2%",
      "2%"
    ),
    density = c(
      0.008577154, 0.008661514, 0.008661514, 0.008764242,
      0.008764242, 0.008877907, 0.008877907, 0.008968337,
      0.008968337, 0.008918499, 0.008918499, 0.008955224, 0.008955224,
      0.009093437, 0.009093437, 0.009235578, 0.009235578, 0.009362444,
      0.009362444, 0.009522395, 0.009522395, 0.009719645, 0.009719645,
      0.010011171, 0.010011171, 0.010173328, 0.010173328, 0.009743716,
      0.009743716, 0.010035448, 0.010035448, 0.010049866
    ),
    status = c(
      "pre", "post", "pre", "post", "pre", "post", "pre", "post",
      "pre", "post", "pre", "post", "pre", "post", "pre", "post",
      "pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre",
      "post", "pre", "post", "pre", "post", "pre", "post"
    )
  )

@Camille 的想法是对的,你不需要在 aes()

中调用 simulation3_mod_500$
ggplot(simulation3_mod_500, aes(x = percentP , y = density, fill = status)) +
  geom_boxplot() +
  facet_wrap(~percentP, scales = "free_x")  

我添加 scales = "free_x" 是为了让两个图表都没有 1% 和 2%,它们只包含 facet 中存在的 x 值。