使用条形图对 x 轴进行分组

group x axis using barplot

这是我的数据(data.txt):

    S1    S2   S3    S4   S5   S6    S7   S8    S9   S10  S11
T1  1.6   17   2.2   1    4.4  23.8  0.2  2.8   3.2  0.4  18.2
T2  0     3.5  1.5   0.5  4    3     6.5  21.6  0.5  1    18.6
T3  0     0    0     4.2  4.2  41.7  4.2  0     8.3  4.2  4.2
T4  4     0    0     0    0    12    4    4     4    16   20
T5  31.3  6.3  12.5  0    0    12.5  0    0     6.3  0    0
T6  12.5  0    0     18.8 0    12.5  0    0     6.3  6.3  0

这是我的代码:

data =  read.table("C:/Users/Irwan/Desktop/graph_plot/data.txt", header = TRUE, sep = "\t", row.names = 1)

attach(data)

column = colnames(data)
rows = rownames(data)

x = barplot(as.matrix(data), xaxt = "n", beside = TRUE, legend = rows, ylim = c(0, 50), density = c(30,30,30,30,70,100), angle = c(0,45,90,135,0,0))

label = as.vector(column)

text(x = x + 1.20, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

遗憾的是,我无法正确分组 x 轴标签。

我已经尝试了很多解决方案,这就是我目前得到的。谁能指导我如何对每 6 个柱的结果进行分组(例如:前 6 个柱为 S​​1)。请原谅我,我在 R 方面不是很好,我只能使用预安装的 R 包,因为由于未知原因我无法安装任何新包。谢谢。

已更新

我对我的代码做了一点改动,以便于重现。我的新代码:

y = matrix (1:15, ncol = 5)

x = barplot(as.matrix(y), xaxt = "n", beside = TRUE, legend = c("T1","T2","T3"), ylim = c(0,30), density = c(30,30,30), angle = c(0,45,90))

label = rep(c("S1","S2","S3","S4","S5"), each = 3)

text(x = x + 0.4, y = -1.25, xpd = TRUE, cex = 0.6, srt = 90, label, pos = 2)

如果我没看错,请将您的标签替换为:

label = rep(column,each=6)

应该提供所需的结果。

编辑;

如果每组只需要一个标签

label = as.vector(rbind("",paste("S",1:5,sep=""),""))