如何固定Y量表以在Barplot中包含不同的级级订单

发布于 2025-02-11 00:54:08 字数 2323 浏览 0 评论 0原文

我遇到了一些麻烦,用ggplot2绘制数据框架。

我对绘图并没有问题。我的分布与我想要的完全相同。但是,该图仅显示幅度顺序的一部分。数据框显示-07,-08和-09的数据。我尝试了下面的图表来使用空白,断裂和一些转换,但结果不好。在下面,您可以找到我想绘制的示例。我只与R一起工作,因此,如果您只能共享R代码,我将不胜感激。

这是示例代码:

##plot data
ggplot(data, aes(x = reorder(Treatment, -mean), y = mean))+
  geom_bar(aes(x = reorder(Treatment, -mean), y= mean), stat="identity", fill="black" , alpha=0.5)+
  geom_errorbar(aes(x = reorder(Treatment, -mean), ymin=mean-se, ymax=mean+se), width=0.4, colour="black", alpha=0.9, size=1.3)+
  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 = 1,
    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), 
    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.15, "cm"), 
    legend.background = element_rect(colour = NA), 
    legend.spacing = 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 = c(.80, .88), 
    legend.direction = NULL, 
    legend.justification = "center", 
    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 several troubles plotting my data frame with ggplot2.

I haven't problems with the plotting itself. I have exactly the same distribution that I want. However, the plot shows only one part of the magnitude orders. The dataframe shows data at -07, -08, and -09. I tried the chart below to use gaps, breaks, and some transformations but with bad results. Below you can find an example of what I want to plot. I only work with R, so I will appreciate if you can share only R codes.

enter image description here

Here is the example code:

##plot data
ggplot(data, aes(x = reorder(Treatment, -mean), y = mean))+
  geom_bar(aes(x = reorder(Treatment, -mean), y= mean), stat="identity", fill="black" , alpha=0.5)+
  geom_errorbar(aes(x = reorder(Treatment, -mean), ymin=mean-se, ymax=mean+se), width=0.4, colour="black", alpha=0.9, size=1.3)+
  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 = 1,
    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), 
    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.15, "cm"), 
    legend.background = element_rect(colour = NA), 
    legend.spacing = 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 = c(.80, .88), 
    legend.direction = NULL, 
    legend.justification = "center", 
    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))

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

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

发布评论

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

评论(1

偏爱自由 2025-02-18 00:54:08
library(ggbreak)

df <- data.frame(treatment = factor(1:4),
                 y = c(100000, 1000, 100, 10),
                 se = c(10000, 100, 10, 1))

ggplot(df, aes(x=treatment, y=y)) +
  geom_col() +
  geom_errorbar(aes(ymin=y-se, ymax=y+se), width=.4) +
  scale_y_cut(breaks=c(25, 150, 1600))

library(ggbreak)

df <- data.frame(treatment = factor(1:4),
                 y = c(100000, 1000, 100, 10),
                 se = c(10000, 100, 10, 1))

ggplot(df, aes(x=treatment, y=y)) +
  geom_col() +
  geom_errorbar(aes(ymin=y-se, ymax=y+se), width=.4) +
  scale_y_cut(breaks=c(25, 150, 1600))

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文