2

棒グラフの列に名前を追加しようとしています...各グループに同じ名前を共有する 2 つの棒があります..

私は次のようなコードを使用しています:

l<-c(.6286, .2212, .9961, .5831, .8703, .6990, .9952, .9948)

r<-c(.2721, .5663, .0, .3961, .0696, .1180, .0, .0)

tab<-rbind(l,r)

plot<-barplot(tab, beside=TRUE, axisnames=FALSE, main = 'Time Spent Left vs. Right', sub = 'Female 2c', xlab= 'Days After Entry', ylab = 'Proportion of Time Spent', col=c('blue', 'red'), ylim = c(0,1))
legend('topleft', .8,  c('Left' , 'Right'), pch=c(.8), col=c('blue', 'red'))
names.arg = jd2c$d.in.p

names.arg=c(3,4,5,6,6,7,10,11) #listed for informational purposes, same as jd2c$d.in.p

jd2c$d.in.p も上にリストされています。何らかの理由で、names.arg 関数が期待どおりに動作していないようです。bar plot() 関数の括弧内に入れても..

私は何を間違っていますか?

ありがとうございました!

4

2 に答える 2

1

names.arg関数の引数としてではbarplotなく、完全に別の変数として定義しています。これは括弧の外にあります。これ:

plot<-barplot(tab, beside=TRUE, axisnames=FALSE, main = 'Time Spent Left vs. Right', sub = 'Female 2c', xlab= 'Days After Entry', ylab = 'Proportion of Time Spent', col=c('blue', 'red'), ylim = c(0,1))
legend('topleft', .8,  c('Left' , 'Right'), pch=c(.8), col=c('blue', 'red'))
names.arg = jd2c$d.in.p

次のようにする必要があります。

plot<-barplot(tab, beside=TRUE, axisnames=FALSE, main = 'Time Spent Left vs. Right', sub = 'Female 2c', xlab= 'Days After Entry', ylab = 'Proportion of Time Spent', col=c('blue', 'red'), ylim = c(0,1), names.arg = jd2c$d.in.p)
legend('topleft', .8,  c('Left' , 'Right'), pch=c(.8), col=c('blue', 'red'))

axisnames=TRUE名前が表示されるように設定する必要もあります。

于 2012-07-16T18:17:35.443 に答える
1

データと設定をnames.arg適切に使用するとaxisnames=TRUE、妥当な結果が得られます。他にもいくつか微調整しました (las=1軸ラベルを水平にするように設定し、凡例でfillはなく使用colし、 を取り除きましたpch=0.8)。

par(las=1)
bnames <- c(3,4,5,6,6,7,10,11) #listed for informational purposes, same as jd2c$
plot<-barplot(tab, beside=TRUE, axisnames=TRUE,
              main = 'Time Spent Left vs. Right',
              sub = 'Female 2c', xlab= 'Days After Entry',
              ylab = 'Proportion of Time Spent',
              col=c('blue', 'red'), ylim = c(0,1),
              names.arg=bnames)
legend('topleft', cex=1,  c('Left' , 'Right'), fill=c('blue', 'red'))

ここに画像の説明を入力

于 2012-07-16T18:12:48.360 に答える