X 軸上の 2 つの異なる要因によって分類されるボックスプロットを R-cran で作成しようと取り組んでいます。私の問題は、凡例を使用して2〜3レベルしかない2番目の因子にラベルを付けながら、グラフ全体に適切に広がる+20レベルの1つの因子のラベルを作成することにあります。
これは、実際のデータセットを大まかに模倣したテスト スクリプトです。
d<-data.frame(x=rnorm(1500),f1=rep(seq(1:20),75),f2=rep(letters[1:3],500))
# first factor has 20+ levels
d$f1<-factor(d$f1)
# second factor a,b,c
d$f2<-factor(d$f2)
boxplot(x~f2*f1,data=d,col=c("red","blue","green"),frame.plot=TRUE,axes=FALSE)
# y axis is numeric and works fine
yts=pretty(d$x,n=5)
axis(2,yts)
# I know this doesn't work; what I'd like is to spread the factors out
# so the each group of three(a,b,c) is labeled correctly
axis(1,at=seq(1:20))
# Use the legend to handle the f2 factor labels
legend(1, max(d$x), c("a", "b","c"),fill = c("red", "blue","green"))
助けてくれてありがとう