r语言组合图如何调整柱形图之间的间距
可以通过ggplot2包中的geom_bar()函数中的参数width来调整柱形图之间的间距。默认情况下,width为0.9,可以减小它的值来增加间距,或者增加它的值来减小间距。例如,设置width为0.5:
library(ggplot2)
# 创建一个DataFrame
df <- data.frame(
x = c("A", "B", "C", "D"),
y1 = c(10, 20, 30, 40),
y2 = c(20, 30, 40, 50)
)
# 绘制组合图
ggplot(df, aes(x, y1)) +
geom_bar(stat = "identity", position = position_dodge(width = 0.5)) +
geom_bar(aes(y = y2), stat = "identity", position = position_dodge(width = 0.5))
这会将柱形图之间的间距减小,使它们更加紧凑。可以尝试不同的width值,以找到最合适的间距大小。
原文地址: https://www.cveoy.top/t/topic/b5VX 著作权归作者所有。请勿转载和采集!