2016-10-03 5 views
0

私は、異なる範囲と長さがnのベクトルを持つ複数の列のデータフレームを持っています(nとしましょう)。各ボックスプロットの下に各変数の異なるx軸を表示したい。私はfacet_gridfacet_wrapを試しましたが、それは共通のx軸を与えます。追加のポイントを持つRのボックスプロット

d <- data.frame(matrix(rnorm(10000), ncol = 20)) 

point_var <- rnorm(20) 
plot.data <- gather(d, variable, value) 
plot.data$test_data <- rep(point_var, each = nrow(d)) 

ggplot(plot.data, aes(x=variable, y=value)) + 
geom_boxplot() + 
geom_point(aes(x=factor(variable), y = test_data), color = "red") + 
coord_flip() + 
xlab("Variables") + 
theme(legend.position="none") 
+0

質問は何ですか? –

+0

私はそれぞれのプロットに異なるx軸が必要です – Rajan

+0

多分facet_wrap(〜yourvar、scales = 'free_x')? – lbusett

答えて

1

あなたはプロット上のx軸のテキストを持つ、およびビットはグラフの順序持つと一緒に暮らすことができる場合はめちゃめちゃをアップこれは仕事ができる:

これは私が試したものです
library(grid) 
p = ggplot(plot.data, aes(x = 0, y=value)) + 
    geom_boxplot() + 
    geom_point(aes(x = 0, y = test_data), color = "red") + 
    facet_wrap(~variable, scales = "free_y", switch = "y") + 
    xlab("Variables") + 
    theme(legend.position="none") + theme_bw() + theme(axis.text.x=element_blank()) 

    print(p, vp=viewport(angle=270, width = unit(.75, "npc"), height = unit(.75, "npc"))) 

実際には、コードを反転することなくグラフを作成しているので、scales = 'free_y'が機能し、ストリップラベルの位置をスワイジしてグラフを回転します。

上記のグラフがわかりにくければ(わかりやすい)、私は単一のプロットのリストを作成し、それをgrid.arrangeと一緒に配置することを検討します。

HTH、

ロレンツォ

関連する問題