我创建了一个条形图,但需要更改x轴标签,以便前两个条形图有一个标签,后两个条形条形图有第二个标签。目前,4个标绘条中的每一个都被单独标记,但每个标签重复两次。对不起,如果术语不正确,我对这整个R事物都是新手。
我输入的代码是:
attach(flydiets)
y <- matrix(protein,nrow = 100, ncol = 4, byrow = FALSE)
y[ , c(1,2,3,4)] <- y[ , c(1,3,2,4)]
means <- apply(y,2,mean)
tags = c("25°", "25°","28°", "28°")
barx <- barplot(means, beside=TRUE,col=c("white","grey"),
ylim=c(0,600), names.arg=tags, axis.lty=1, xlab="Temperature (°C)",
ylab="Protein Consumed (µg)")
sd <- apply(y,2,sd)## calculate a standard deviation for each column of y
sd <- matrix(sd,2,2) ## arrange them as a 2 x 2 matrix
se <- sd/sqrt(100) ## convert them to standard errors
arrows(barx,means+1.96*se, barx, means-1.96*se, angle=90, code=3, length=0.1)
legend("topright", legend=c("Male", "Female"), fill=c("white", "grey"), cex=0.8)
任何帮助将不胜感激。干杯
答案 0 :(得分:0)
以下是原始数据集的简化样本。
“性别”, “临时”, “碳水化合物”, “蛋白质”
“M”,“25”,396.075,358.28
“M”,“25”,252.70,204.70
“M”,“25”,441.81,461.86
“M”,“25”,430.88,374.67
“M”,“25”,520.46,439.10
“M”,“25”,484.45,561.66
“M”,“28”,590.17,429.98
“M”,“28”,383.23,517.82
“M”,“28”,431.945,289.22
“M”,“28”,410.61,530.89
“M”,“28”,622.14,533.25
“M”,“28”,509.58,425.89
“F”,“25”,489.68,209.87
“F”,“25”,451.03,34.30
“F”,“25”,461.01,283.88
“F”,“25”,715.74,506.62
“F”,“25”,576.33,476.30
“F”,“28”,450.12,452.56
“F”,“28”,498.53,376.46
“F”,“28”,517.02,303.82
“F”,“28”,355.84,78.65
“F”,“28”,404.07,229.88
“F”,“28”,537.57,253.27
感谢您的帮助