1

我创建了一个条形图,但需要更改 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)

任何帮助,将不胜感激。干杯

4

1 回答 1

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

谢谢你的帮助

于 2013-04-25T04:44:11.797 回答