首页 > 解决方案 > ggplot2 从绝对值值中获取条形图

问题描述

嘿,我有以下代码:

t<- rep(c(1,2,4,8,16,24,32),4)
y1 <- c(1,1.99,4.01,7.94, 15.98, 23.74, 27.17)
y2 <- c(1,2, 4, 7.98, 15.92, 23.77, 30.37)
y3 <- c(1,2.01, 4.04, 8.12, 16.19, 24.03, 31.14)
y4 <- c(1,1.96, 3.81, 6.46, 9.81, 10.26, 9.15)
total <- c(y1,y2,y3,y4)
rel.df <- data.frame(color=rep(c("a", "b", "c", "d"), each=7),t,total)
ggplot(rel.df, aes(x=t, y = total, fill = color)) +
  geom_bar(position = "dodge", stat ="identity", width=0.5) 

我想绘制一个条形图,将我的每个 ys 显示为关于 t 值的单独组,我目前得到的是:是否有可能将组与 t 值(1,2, 4,8,16,24,32),没有扩展 x 轴?所以我想要,x 值具有相同的图形距离,例如,第 4 组与第 2 组的距离与第 8 组的距离一样远。

在此处输入图像描述

标签: rggplot2statistics

解决方案


推荐阅读