我有两个3x2矩阵A和B:
A:
n2 n3
Part1 1 5
Part2 2 6
Part3 3 7
B:
n2 n3
Part1 5 1
Part2 6 2
Part3 7 3
我想创建堆叠条,我通过以下方式完成:
d1 <- read.csv("A.csv", header=T, dec=".",sep = " ")
d1 <- subset(d1, select = c(n2, n3))
d2 <- read.csv("B.csv", header=T, dec=".",sep = " ")
d2 <- subset(d2, select = c(n2, n3))
d <- cbind(d1[,1],d2[,1],d1[,2],d2[,2])
barplot(d, col=c("lawngreen","firebrick","deepskyblue"),
space=c(0,0,0.2,0), xaxt = "n", yaxt="n",ylim = c(0, 25))
x_axis_range <- c(2,3)
x_axis_labels <- c("2", "3")
axis(1,at = x_axis_range, labels = x_axis_range)
y_axis_range <- c(0,2,4,6,25)
y_axis_labels <- c("0","2","4","6","25")
axis(2,at = y_axis_range, labels = y_axis_labels, las=2)
但是,我希望2和3在每个分组的条形下显示为居中。我该怎么办?