【发布时间】:2020-04-21 09:33:06
【问题描述】:
在我的分组条形图的可重现示例下方。我正在为组之间的空间/填充而苦苦挣扎。我已经在 stackoverflow 上找到了一些问题,例如 this 和 here。
我还尝试将geom_bar(position= .. 参数设置为"dodge" 或dodge_position(0.5) 以及我的条的宽度。但是我不想再增加我的栏的宽度。是否有任何解决方案,例如更改离散 x 轴的大小以减少图 1 中的标记空间? 更新: 减少了代码,使其对于最小的可重现示例更加精简。问题依旧
library(ggplot2)
library(ggthemes)
library(dplyr)
algorithm <- c(rep("0_DT",2),rep("1_RF",2),rep("2_MLP",2))
target <- rep(c("Some Data","Some Other Data"),3)
value <- runif(6,85,95) # Simulated Accuracies
CI_lower <- value - 5
CI_upper <- value + 5
data <- data.frame(target,algorithm,value,CI_lower,CI_upper)
ggplot(data, aes(fill=algorithm, y=value, x=target)) +
geom_bar(position=position_dodge(0.75), stat="identity", width = 0.65)+ theme_classic()+
scale_fill_manual("Algorithm",
values = alpha(c("0_DT" = "#20639B", "1_RF" = "#3CAEA3", "2_MLP" = "#F6D55C"),0.8),
labels=c("DT","RF","MLP"))+
scale_y_continuous("Accuracy in %",limits = c(0,100),oob = rescale_none,
# breaks= sort(c(seq(0,90,10),h)),
breaks= seq(0,100,10),
expand = c(0,0))
这是我的条形图图 1
【问题讨论】:
-
您尝试过
position_dodge或position_dodge2参数吗?preserve和padding可能会有所帮助 -
您好,感谢您的评论。我刚刚尝试了
position=position_dodge2(0.4,preserve="single",padding=.05)的不同组合,将填充更改为 0,但是条形和 y 轴之间以及两组条形之间的距离始终保持不变。 -
用
scale_x_discrete(expand=c(0.3,0.1))here 找到了一些东西来减少左边(y 轴)和右边的空间。然而,酒吧组之间的空间仍然有点高