简体   繁体   English

如何为2个绘制的条创建1个x轴标签

[英]How to create 1 x-axis label for 2 plotted bars

I've created a bar plot but need to change the x-axis labels so that there's one label for the first two bars and a second label for the next two bars. 我已经创建了一个条形图,但是需要更改x轴标签,以便前两个条形有一个标签,接下来的两个条形有第二个标签。 At present each of the 4 plotted bars are individually labelled, but each label is repeated twice. 目前,四个标绘的条形图分别被单独标记,但是每个标记重复两次。 Sorry if the terminology isn't correct, I'm new to this whole R thing. 抱歉,如果术语不正确,那么我对这整个R都是陌生的。

The code I've entered is: 我输入的代码是:

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)

Any help would be appreciated. 任何帮助,将不胜感激。 Cheers 干杯

Below is a reduced sample of data set from the original. 以下是原始数据集的简化样本。

"sex","temp","carbohydrate","protein" “性别”,“温度”,“碳水化合物”,“蛋白质”

"M","25", 396.075, 358.28 “ M”,“ 25”,396.075、358.28

"M","25", 252.70, 204.70 “ M”,“ 25”,252.70、204.70

"M","25", 441.81, 461.86 “ M”,“ 25”,441.81、461.86

"M","25", 430.88, 374.67 “ M”,“ 25”,430.88、374.67

"M","25", 520.46, 439.10 “ M”,“ 25”,520.46、439.10

"M","25", 484.45, 561.66 “ M”,“ 25”,484.45、561.66

"M","28", 590.17, 429.98 “ M”,“ 28”,590.17,429.98

"M","28", 383.23, 517.82 “ M”,“ 28”,383.23,517.82

"M","28", 431.945, 289.22 “ M”,“ 28”,431.945,289.22

"M","28", 410.61, 530.89 “ M”,“ 28”,410.61、530.89

"M","28", 622.14, 533.25 “ M”,“ 28”,622.14,533.25

"M","28", 509.58, 425.89 “ M”,“ 28”,509.58、425.89

"F","25", 489.68, 209.87 “ F”,“ 25”,489.68,209.87

"F","25", 451.03, 34.30 “ F”,“ 25”,451.03,34.30

"F","25", 461.01, 283.88 “ F”,“ 25”,461.01,283.88

"F","25", 715.74, 506.62 “ F”,“ 25”,715.74,506.62

"F","25", 576.33, 476.30 “ F”,“ 25”,576.33,476.30

"F","28", 450.12, 452.56 “ F”,“ 28”,450.12,452.56

"F","28", 498.53, 376.46 “ F”,“ 28”,498.53,376.46

"F","28", 517.02, 303.82 “ F”,“ 28”,517.02,303.82

"F","28", 355.84, 78.65 “ F”,“ 28”,355.84,78.65

"F","28", 404.07, 229.88 “ F”,“ 28”,404.07,229.88

"F","28", 537.57, 253.27 “ F”,“ 28”,537.57,253.27

Thanks for your help 谢谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM