[英]How to customize the range of values in a y-axis of a geom_bar plus geom_error bar plot
因此,对于我的数据,默认的 ggplot 给出了;
现在,我希望我在 y 轴上的值范围是; "0.5","1.0","1.5" 以便更好地观察似乎在 0.8 和 1.0 之间的图的趋势。
为此,我将以下代码添加到我的 plot;
scale_y_discrete(limits = c(0.5,1.5), breaks = c(0.5, 1.0, 1.5))
但是,我没有得到我想要的结果,即在 plot 上视觉消除 0 到 0.5,我得到了;
如果没有可重现的示例,我不得不尝试重新创建您的 plot:
library(ggplot2)
library(ggpubr)
set.seed(69)
Regions <- rep(paste("Region", 1:10), each = 4)
Regions <- factor(Regions, levels = paste("Region", 1:10))
Index <- rep(c("HDI", "II", "HI", "EI"), 10)
Index <- factor(Index, levels = c("HDI", "II", "HI", "EI"))
Mean <- runif(40, .85, .95)
Upper <- Mean + 0.015
Lower <- Mean - 0.01
Upper[Index == "HI" | Index == "EI"] <- NA
Lower[Index == "HI" | Index == "EI"] <- NA
df <- data.frame(Regions, Index, Mean, Lower, Upper)
p <- ggplot(df, aes(Regions, Mean, fill = Index)) +
geom_col(position = "dodge", width = 0.8, colour = "#6b6f74") +
geom_errorbar(aes(ymin = Lower, ymax = Upper), position = "dodge") +
scale_fill_manual(values = c("#fae4ba", "#dba115", "#aba8a7", "#447ba4")) +
theme_pubr() +
theme(legend.position = "top") +
labs(title = "Regional population distribution by social indexes",
y = "Mean +- SD of Crude Rate")
p
毕竟,我得出的结论是你只是在寻找coord_cartesian
:
p + coord_cartesian(ylim = c(0.75, 1.05))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.