如何修复Y量表以在条图中包含错误条?

发布于 2025-02-12 08:17:06 字数 2222 浏览 1 评论 0 原文

我对图的第二列有问题。错误栏显示不完整。有一种解决这个问题的方法吗?我需要该情节与下面完全相同。这是示例代码和结果。谢谢。

ggplot(data, aes(x = reorder(Treatment, -mean), y = mean, fill = Grapevine)) +
  geom_col(aes(x = reorder(Treatment, -mean), y = mean),
    stat = "identity", position = "dodge"
  ) +
  geom_errorbar(aes(
    x = reorder(Treatment, -mean), ymin = mean - se,
    ymax = mean + se
  ),
  width = 0.1,
  position = position_dodge(0.9)
  ) +
  scale_y_cut(breaks = c(2.0E-09, 2.0E-08, 1.0E-07)) +
  scale_y_continuous(breaks = c(0, 6.0e-09, 6.0e-08, 6.0e-07)) +
  theme(
    line = element_line(
      colour = "black", size = 1,
      linetype = 1, lineend = "butt"
    ),
    rect = element_rect(
      fill = "white", colour = "black",
      size = 1, linetype = 1
    ),
    aspect.ratio = 0.6,
    plot.background = element_rect(fill = "white"), plot.margin = margin(1, 1, 1, 1, "cm"), axis.text = element_text(size = rel(2.5), colour = "#000000", margin = 1), strip.text = element_text(size = rel(0.8)), axis.line = element_blank(), axis.text.x = element_text(vjust = 0.2, angle = 90), axis.text.y = element_text(hjust = 1), axis.ticks = element_line(colour = "#000000", size = 1.2), axis.title.x = element_text(size = 30, vjust = 0.5), axis.title.y = element_text(size = 30, angle = 90), axis.ticks.length = unit(0.1, "cm"), legend.background = element_rect(colour = NA), legend.margin = unit(0.15, "cm"), legend.key = element_rect(fill = "grey95", colour = "white"), legend.key.size = unit(1.2, "lines"), legend.key.height = NULL, legend.key.width = NULL, legend.text = element_text(size = rel(2.0)), legend.text.align = NULL, legend.title = element_text(size = rel(2.0), face = "bold", hjust = 0), legend.title.align = NULL, legend.position = "right", legend.direction = NULL, legend.justification = "right", legend.box = NULL, panel.background = element_rect(
      fill = "#ffffff", colour = "#000000",
      size = 2, linetype = "solid"
    ), panel.border = element_rect(colour = "black", fill = NA, size = 2),
  ) +
  ylab(expression(Lp[r] ~ (m ~ s^-1 ~ Mpa^-1))) +
  xlab(expression(Treatment))

“

I have a problem with the second column of the plot. The error bar showed incomplete. There is a way to fix this? I need that the plot be exactly as below. Here is the example code and the result. Thanks.

ggplot(data, aes(x = reorder(Treatment, -mean), y = mean, fill = Grapevine)) +
  geom_col(aes(x = reorder(Treatment, -mean), y = mean),
    stat = "identity", position = "dodge"
  ) +
  geom_errorbar(aes(
    x = reorder(Treatment, -mean), ymin = mean - se,
    ymax = mean + se
  ),
  width = 0.1,
  position = position_dodge(0.9)
  ) +
  scale_y_cut(breaks = c(2.0E-09, 2.0E-08, 1.0E-07)) +
  scale_y_continuous(breaks = c(0, 6.0e-09, 6.0e-08, 6.0e-07)) +
  theme(
    line = element_line(
      colour = "black", size = 1,
      linetype = 1, lineend = "butt"
    ),
    rect = element_rect(
      fill = "white", colour = "black",
      size = 1, linetype = 1
    ),
    aspect.ratio = 0.6,
    plot.background = element_rect(fill = "white"), plot.margin = margin(1, 1, 1, 1, "cm"), axis.text = element_text(size = rel(2.5), colour = "#000000", margin = 1), strip.text = element_text(size = rel(0.8)), axis.line = element_blank(), axis.text.x = element_text(vjust = 0.2, angle = 90), axis.text.y = element_text(hjust = 1), axis.ticks = element_line(colour = "#000000", size = 1.2), axis.title.x = element_text(size = 30, vjust = 0.5), axis.title.y = element_text(size = 30, angle = 90), axis.ticks.length = unit(0.1, "cm"), legend.background = element_rect(colour = NA), legend.margin = unit(0.15, "cm"), legend.key = element_rect(fill = "grey95", colour = "white"), legend.key.size = unit(1.2, "lines"), legend.key.height = NULL, legend.key.width = NULL, legend.text = element_text(size = rel(2.0)), legend.text.align = NULL, legend.title = element_text(size = rel(2.0), face = "bold", hjust = 0), legend.title.align = NULL, legend.position = "right", legend.direction = NULL, legend.justification = "right", legend.box = NULL, panel.background = element_rect(
      fill = "#ffffff", colour = "#000000",
      size = 2, linetype = "solid"
    ), panel.border = element_rect(colour = "black", fill = NA, size = 2),
  ) +
  ylab(expression(Lp[r] ~ (m ~ s^-1 ~ Mpa^-1))) +
  xlab(expression(Treatment))

bar plot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2025-02-19 08:17:06

我们可以用 lims() ,但是在这种情况下,使用 explead_limits() 自动适应限制以确保该限制的限制值在图中可见。

示例:

ggplot(...) +
  geom_point() +
  expand_limits(y = 8.5e-7) # a manually hardcoded location
ggplot(...) +
  geom_point() +
  expand_limits(y = max(data$mean+data$se) ) # a limit based on your actual data

We can explicitly set the plot's limits with lims(), but in this case it is more elegant to use expand_limits() which automatically adapts the limits to ensure that a certain value will be visible in the plot.

Examples:

ggplot(...) +
  geom_point() +
  expand_limits(y = 8.5e-7) # a manually hardcoded location
ggplot(...) +
  geom_point() +
  expand_limits(y = max(data$mean+data$se) ) # a limit based on your actual data
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文