うまく機能するエラーバー付きの箱ひげ図を作成するための以下の関数が与えられました。
ただし、軸ラベルを追加する必要があり、このようなコードを追加する場所を見つけようとして2日かかりました
# col=c(2,7),ylab="Relative Fitness",xlab="Block")
error.bars<-function(Response,x1,x2) {
mean.table<-tapply(Response,list(x1,x2),mean)
mean.table[is.na(mean.table)]<-0
var.table<-tapply(Response,list(x1,x2),var)
n.table<-tapply(Response,list(x1,x2),length)
std.errors<-sqrt(var.table/n.table)
std.errors[is.na(std.errors)]<-0
biggest.value<-max(mean.table+std.errors)
bartable<-barplot(mean.table,beside=TRUE,
ylim=c(0,biggest.value+1))
errbar.width<-(max(bartable)-min(bartable))/50
for(i in 1:length(mean.table[,1])) {
for(j in 1:length(mean.table[1,])) {
lines(c(bartable[i,j],bartable[i,j]),
c(mean.table[i,j]-std.errors[i,j],
mean.table[i,j]+std.errors[i,j]))
lines(c(bartable[i,j]-errbar.width,
bartable[i,j]+errbar.width),
c(mean.table[i,j]+std.errors[i,j],
mean.table[i,j]+std.errors[i,j]))
lines(c(bartable[i,j]-errbar.width,
bartable[i,j]+errbar.width),
c(mean.table[i,j]-std.errors[i,j],
mean.table[i,j]-std.errors[i,j]))
}
}
}
どんなヒントでも大歓迎です
私はRとこのサイトが初めてなので、メッセージを伝える方法がわかりません。私のデータはかなり単純明快で、このように見えます。n=3 Blocks、n=33 Lines、n=2 は Sex で、私の y 変数は Fitness です。以前に投稿した errorbars 関数の関数で boxplot を作成できました。ただし、私がやろうとしているのは、関数に x 軸と y 軸のラベルを追加することだけです。簡単そうに見えますが、わかりません。
head(OzGLM) Block Line Sex Fitness 1 1 3 1 0.6865626 2 1 3 2 0.4874816 3 1 4 1 0.4219811 4 1 4 2 0.3829161 5 1 5 1 0.6071388 6 1 5 2 0.4432990