1

棒グラフを作成しましたが、x 軸のラベルを変更して、最初の 2 つの棒に 1 つのラベルを、次の 2 つの棒に 2 番目のラベルを配置する必要があります。現在、プロットされた 4 つのバーのそれぞれに個別にラベルが付けられていますが、各ラベルは 2 回繰り返されています。用語が正しくない場合は申し訳ありませんが、私はこの 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