2016-10-26 1 views
0

私はここから変更されたコードを使用することによって、私の問題を説明してみましょう:私の例では https://stats.stackexchange.com/questions/22805/how-to-draw-neat-polygons-around-scatterplot-regions-in-ggplot2ggplot2とboxplotdouのプロットを結合するには?

を、私はアイリスデータセットを使用します。 - 同じ寸法で

boxplotdbl not in fight position

私の目的は、ハル散布図にダブルボックスプロット(boxplotdou)をプロットすることである。

私の試みは、これまでのところ、これを生産しています。現在のコードは次のとおりです。

library(ggplot2) 
    library(boxplotdbl) 
    df <- iris 
    find_hull <- function(df) df[chull(df$Sepal.Length, df$Sepal.Width), ] 
    hulls <- ddply(df, "Species", find_hull) 

    plot <- ggplot(data = df, aes(x = Sepal.Length, y = Sepal.Width, colour=Species, fill = Species)) + 
     geom_point() + 
     geom_polygon(data = hulls, alpha = 0.5) + 
     labs(x = "Sepal.Length", y = "Sepal.Width") 
    plot 

    par(new = TRUE) 
    # This is quite close what I'm trying to achieve, without axes. But it is in wrong position 
    #boxplotdou(Sepal.Length~Species, iris, Sepal.Width~Species, iris, factor.labels=FALSE, draw.legend=FALSE, name.on.axis=FALSE, ann = FALSE, axes = FALSE) 
    # This shows the axes, which do not match the underlying plot 
    boxplotdou(Sepal.Length~Species, iris, Sepal.Width~Species, iris, factor.labels=FALSE, draw.legend=FALSE, name.on.axis=FALSE, ann = FALSE) 

私は(... ggplot内の()boxplotdouを挿入しようとしたが、私はエラーを得た:「プロットにoを追加する方法がわからない」

すべてのヘルプは、あなたの額面(新しい= TRUE)した後にこれを入れた後。

-Kari

+0

しないでください。 – tchakravarty

+0

私はggplot2のすべてを試してみたいと思います。ボックスプラットバーとボックスの上限と下限の値を計算する2番目のデータフレームを作成する必要があります。次に、geom_rectでボックスをプロットします。バーはgeom_errorbarでプロットすることができます。 ggstanceパッケージからgeom_errorbarhが必要になる場合があります。 https://github.com/lionel-/ggstance – timcdlucas

答えて

0
par(mar=c(2.850, 3.20, 1.30, 7.40)) 

いただければ幸い、私は良いオーバーレイを得た。 enter image description here se maginsはグラフィック環境に依存することがあります。 私は座標がggplot2とRの基本グラフとの間に互換性がないと考えています。そのため、両方を同じ画像で使用する場合は、手動で調整する必要があります。パッケージboxplotdblはggplot2用ではなく、基本グラフ用です。

関連する問題