2017-01-04 14 views
2

私は以下のようにDataFrameを輸入していますジュリアのGadflyの `Scale.color_discrete_manual`を使ってカラーキーを変更するには?

julia> df 
100×3 DataFrames.DataFrame 
│ Row │ ex1  │ ex2  │ admit │ 
├─────┼─────────┼─────────┼───────┤ 
│ 1 │ 34.6237 │ 78.0247 │ 0  │ 
│ 2 │ 30.2867 │ 43.895 │ 0  │ 
│ 3 │ 35.8474 │ 72.9022 │ 0  │ 
│ 4 │ 60.1826 │ 86.3086 │ 1  │ 
│ 5 │ 79.0327 │ 75.3444 │ 1  │ 
│ 6 │ 45.0833 │ 56.3164 │ 0  │ 
│ 7 │ 61.1067 │ 96.5114 │ 1  │ 
│ 8 │ 75.0247 │ 46.554 │ 1  │ 
⋮ 
│ 92 │ 90.4486 │ 87.5088 │ 1  │ 
│ 93 │ 55.4822 │ 35.5707 │ 0  │ 
│ 94 │ 74.4927 │ 84.8451 │ 1  │ 
│ 95 │ 89.8458 │ 45.3583 │ 1  │ 
│ 96 │ 83.4892 │ 48.3803 │ 1  │ 
│ 97 │ 42.2617 │ 87.1039 │ 1  │ 
│ 98 │ 99.315 │ 68.7754 │ 1  │ 
│ 99 │ 55.34 │ 64.9319 │ 1  │ 
│ 100 │ 74.7759 │ 89.5298 │ 1  │ 

私はy軸とx軸、ex2としてex1を使用して、このDataFrameをプロットしたいです。また、データは第3列の:admitで分類されていますので、:admitの値に基づいて異なる色のドットを付けたいと思います。

私はScale.color_discrete_manualを使って色を設定しましたが、Guide.manual_color_keyを使って色の凡例を変更しようとしました。しかし、それはGadflyが2つのカラーキーを作ったことが分かります。

p = plot(df, x = :ex1, y = :ex2, color=:admit, 
     Scale.color_discrete_manual(colorant"deep sky blue", 
            colorant"light pink"), 
     Guide.manual_color_key("Legend", ["Failure", "Success"], 
           ["deep sky blue", "light pink"])) 

plot1

私の質問はScale.color_discrete_manualを使用する際に色キー凡例を変更する方法ですか?

関連する1つの質問は、Remove automatically generated color key in Gadfly plotです。ここで、2つのレイヤーにGuide.manual_color_keyを使用することをお勧めします。 DataFrameScale.color_discrete_manualを使用すると良いソリューションがありますか?

答えて

1

現在、discussionに基づいて、colorまたはScale.color_discrete_manualによって生成された色の凡例をカスタマイズできないようです。

同じソースから、Mattriksは、「ラベル」として追加の列を使用することを提案しています。カラーキーを変更するのは自然ではありませんが、かなりうまく動作します。

したがって、問題の同じデータセットについては、

plot(df, x = :exam1, y = :exam2, color = :admission, 
    Scale.color_discrete_manual(colorant"deep sky blue", 
           colorant"light pink")) 

plot

df[:admission] = map(df[:admit])do x 
    if x == 1 
     return "Success" 
    else 
     return "Failure" 
    end 
end 

julia> df 
100×4 DataFrames.DataFrame 
│ Row │ exam1 │ exam2 │ admit │ admission │ 
├─────┼─────────┼─────────┼───────┼───────────┤ 
│ 1 │ 34.6237 │ 78.0247 │ 0  │ "Failure" │ 
│ 2 │ 30.2867 │ 43.895 │ 0  │ "Failure" │ 
│ 3 │ 35.8474 │ 72.9022 │ 0  │ "Failure" │ 
│ 4 │ 60.1826 │ 86.3086 │ 1  │ "Success" │ 
│ 5 │ 79.0327 │ 75.3444 │ 1  │ "Success" │ 
│ 6 │ 45.0833 │ 56.3164 │ 0  │ "Failure" │ 
│ 7 │ 61.1067 │ 96.5114 │ 1  │ "Success" │ 
│ 8 │ 75.0247 │ 46.554 │ 1  │ "Success" │ 
⋮ 
│ 92 │ 90.4486 │ 87.5088 │ 1  │ "Success" │ 
│ 93 │ 55.4822 │ 35.5707 │ 0  │ "Failure" │ 
│ 94 │ 74.4927 │ 84.8451 │ 1  │ "Success" │ 
│ 95 │ 89.8458 │ 45.3583 │ 1  │ "Success" │ 
│ 96 │ 83.4892 │ 48.3803 │ 1  │ "Success" │ 
│ 97 │ 42.2617 │ 87.1039 │ 1  │ "Success" │ 
│ 98 │ 99.315 │ 68.7754 │ 1  │ "Success" │ 
│ 99 │ 55.34 │ 64.9319 │ 1  │ "Success" │ 
│ 100 │ 74.7759 │ 89.5298 │ 1  │ "Success" │ 

は次に、この新しいコラムScale.color_discrete_manualを使用してデータをカラー:私たちは、1つの以上の列を追加します

関連する問題