我创建了一个条形图,但需要更改 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)
任何帮助,将不胜感激。干杯