2011-08-03 2 views
8

GGallyパッケージのggpairs関数にパラメータを指定して、すべてではない変数の一部にログスケールを使用できますか?ログスケールを使用するようggpairsに指示できますか?

+0

この目的でaes()関数を使用してみましたか?ヘルプページには、ggpairsに特別なログ機能があることが示唆されているものは何もありませんが、典型的なggplotの規約を使用すると想定されている可能性があります。 –

答えて

9

次のようなパラメータを提供することはできません(理由は散布図を作成する機能がスケールすることなく、事前に定義されていることで、ggally_pointsを参照)、しかし、あなたはgetPlotputPlotを使用して、後でスケールを変更することができます。例:

custom_scale <- ggpairs(data.frame(x=exp(rnorm(1000)), y=rnorm(1000)), 
upper=list(continuous='points'), lower=list(continuous='points')) 
subplot <- getPlot(custom_scale, 1, 2) # retrieve the top left chart 
subplotNew <- subplot + scale_y_log10() # change the scale to log 
subplotNew$type <- 'logcontinuous' # otherwise ggpairs comes back to a fixed scale 
subplotNew$subType <- 'logpoints' 
custom_scale <- putPlot(custom_fill, subplotNew, 1, 2) 
+0

解決策をありがとう、チャートを操作する方法を知っているのは良いことです。私は後で試してみる。今のところ、新しいログ変数を導入する方が簡単です。 –

2

これは本質的にJean-Robertと同じ回答ですが、はるかにシンプル(近づきやすい)です。私はそれが新しい機能であるかどうかわかりませんが、getPlotまたはputPlotをもう使用する必要がないようです。ここで

custom_scale[1,2]<-custom_scale[1,2] + scale_y_log10() + scale_x_log10()

大きなマトリックス全体に適用する機能です。プロットの行数とプロットの名前を指定します。

scalelog2<-function(x=2,g){ #for below diagonal 
for (i in 2:x){ 
    for (j in 1:(i-1)) { 
     g[i,(j)]<-g[i,(j)] + scale_x_continuous(trans='log2') + 
scale_y_continuous(trans='log2') 
         } } 
for (i in 1:x){ #for the bottom row 
     g[(x+1),i]<-g[(x+1),i] + scale_y_continuous(trans='log2') 
         } 
for (i in 1:x){ #for the diagonal 
     g[i,i]<-g[i,i]+ scale_x_continuous(trans='log2') } 
    return(g) } 
+0

このオプションは、ggplot2 versoin 2.0.0とGGallyバージョン1.0.1として動作します。 – Jthorpe

+1

このコードは2以外の値では機能しません。また、なぜ "g [(x + 1)、i] "g [x、i]"だけじゃない?!? –

関連する問題