2013-02-22 10 views
7

ベースグラフィックうまくx軸を指定せずにボックスプロットを描画するにはどうすればよいですか?

data(mtcars) 
boxplot(mtcars$mpg) 

enter image description here

しかしqplotがY軸を必要とする単純なコマンドを使用して、箱ひげ図をプロットすることができます。 qplotでベースグラフィックスのboxplotのようなものをどのように実現できますか?このエラーは発生しませんか?

qplot(mtcars$mpg,geom='boxplot') 
Error: stat_boxplot requires the following missing aesthetics: y 

答えて

13

xにダミー値を指定する必要があります。 theme()要素は、x軸のタイトルとティックを削除するために使用されます。

ggplot(mtcars,aes(x=factor(0),mpg))+geom_boxplot()+ 
    theme(axis.title.x=element_blank(), 
    axis.text.x=element_blank(), 
    axis.ticks.x=element_blank()) 

それともqplot()機能使用:

bwplot(~mpg,data =mtcars, 
     par.settings = ggplot2like(),axis=axis.grid) 

enter image description here:またboxplot構文とggplot2-likeテーマを混合するために、latticeExtraを使用することができます

qplot(factor(0),mpg,data=mtcars,geom='boxplot') 

enter image description here

+0

。したがって、qplotはqplot(factor(0)、mtcars $ mpg、geom = 'boxplot')になります。 – userJT

1

あなたはfactor(0)にXの美学を設定し、不要なラベルを削除することで、外観を微調整することができます。

私が見る
ggplot(mtcars, aes(x = factor(0), mpg)) + 
    geom_boxplot() + 
    scale_x_discrete(breaks = NULL) + 
    xlab(NULL) 

enter image description here

+0

これは質問に答えるかもしれませんが、答えを説明して、 – loki

関連する問題