我需要在堆积的条形图中绘制一组数据。数据来自具有三种不同成分(M1,M1BIS,M2,M2BIS,M3和M3BIS)的六个样品,并且已经在三个不同点(表面(S),中心(M)和底部(G))中取得。和两次(0& 32天)。
我需要在堆积的条形图中绘制这些数据(每个样本和时间一个条)以查看三个点中的盐浓度,并且所有条形必须具有相同的长度(以百分比表示)
rdata <-
structure(list(Sample = c("M1", "M1", "M1", "M2", "M2", "M2",
"M3", "M3", "M3", "M1 BIS", "M1 BIS", "M1 BIS", "M2 BIS", "M2 BIS",
"M2 BIS", "M3 BIS", "M3 BIS", "M3 BIS", "M1", "M1", "M1", "M2",
"M2", "M2", "M3", "M3", "M3", "M1 BIS", "M1 BIS", "M1 BIS", "M2 BIS",
"M2 BIS", "M2 BIS", "M3 BIS", "M3 BIS", "M3 BIS"), Composition = c(1L,
1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L), t = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 32L, 32L, 32L, 32L, 32L, 32L, 32L,
32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L), Value = c("1,72",
"1,3", "4,12", "3,7", "2,88", "3,52", "1,38", "2,57", "6,89",
"1,28", "0,85", "4,15", "0,71", "1,47", "4,77", "1,17", "1,37",
"4,76", "4,16", "3,65", "3,39", "3,62", "4,04", "4,37", "2,77",
"2,6", "3,23", "3,1", "3,34", "3,64", "3,68", "2,82", "3,12",
"4,03", "3,87", "4,27"), Point = c("G", "M", "S", "G", "M", "S",
"G", "M", "S", "G", "M", "S", "G", "M", "S", "G", "M", "S", "S",
"M", "G", "S", "M", "G", "S", "M", "G", "S", "M", "G", "S", "M",
"G", "S", "M", "G")), .Names = c("Sample", "Composition", "t",
"Value", "Point"), row.names = c(NA, -36L), class = "data.frame")
答案 0 :(得分:0)
我希望这样的事情。
library(reshape2)
rdata$Value <- gsub(",", ".", rdata$Value)
rdata$Value <- as.numeric(rdata$Value)
rdataWide <- dcast(data=rdata, formula = Point ~ Sample + t, value.var = "Value")
rdataWide[,-1] <- t(t(rdataWide[, -1])/colSums(rdataWide[, -1]))
par(xpd=T)
barplot(as.matrix(rdataWide[, -1]), col=2:4, space = 0.25, width=0.5, las=2)
legend(x = 0.25, y=1.25, legend = rdataWide[,1], col = 2:4, pch = 15, bty = "n", ncol = 3)
它应该是par(xpd=T)
而不是ppar(xpd=T)
,这允许在绘图空间之外渲染。设置为false时,图例会被剪裁。
我还添加了library(reshape2)
电话。我为疏忽道歉。