如何自定义ggplot2中的x轴线,以便根据因素将其断开

时间:2019-06-25 18:38:39

标签: r ggplot2

我正在努力复制我看到的图形的x轴设计。可以使用ggplot2重新创建a轴吗?

我尝试使用lemon软件包,但这并没有完全复制我想要的轴。

我希望x轴看起来像这张图片中的左侧图片

enter image description here

编辑

对不起,很抱歉,我现在按要求编辑了一些示例数据和代码。

tidy_data:

Replicate Group Time
1   Control 0.09997222
2   Control 0.04466667
3   Control 0.08608333
4   Control 0.10712500
5   Control 0.11410000
6   Control 0.69333333
7   Control 0.42383333
8   Control 0.06105556
9   Control 0.08676667
1   Treatment   0.13700000
2   Treatment   0.02983333
3   Treatment   0.49608333
4   Treatment   0.97858333
5   Treatment   0.70900000
6   Treatment   0.18683333
7   Treatment   0.45283333
8   Treatment   1.30220833
9   Treatment   1.39908333

results_tbl:

mean_time   sem         upper_sem   lower_sem   treatment
0.1534459   0.03681368  0.1902596   0.1166323   Control
0.8238021   0.15860139  0.9824035   0.6652007   Treatment

地块代码:

figure = ggplot() +
    geom_quasirandom(
      data = tidy_data,
      aes(x = Group, y = Time, colour = Replicate),
      size = 5,
      varwidth = TRUE
    ) +
    geom_point(
      data = results_tbl,
      aes(x = treatment, y = mean_time),
      colour = "black",
      size = 4
    ) +
    geom_errorbar(
      data = results_tbl,
      aes(x = treatment, ymin = lower_sem, ymax = upper_sem),
      alpha = 1,
      size = 0.1,
      width = 0.1,
      colour = "black"
    ) +
    scale_y_continuous(breaks = scales::pretty_breaks()) +
    labs(x = "", y = "Mean time spent in zone ± SE (mins)") +
    theme_cowplot(font_size = 16, line_size = 1) +
    theme(axis.title.y = element_text(vjust = 2))

0 个答案:

没有答案