2017-07-21 7 views
0

私はグラフをプロットしていますが、私が割り当てるファクタレベルの順序と関数scale_fill_manual()はggplotによって無視されます。ggplotでファクタレベルとscale_fill_manual()引数が無視されるR

データセットは、リポジトリを学ぶUCIマシンで見つけることができますドイツ語クレジットデータセットで、コードは以下の通りです:

german_fct_train$Status_of_existing_account <- factor(german_fct_train$Status_of_existing_account , 
          levels = c("No_Account" , "less_than_0" , "between_0_and_200" , "greater_equal_to_200")) 
german_fct_train$Class <- factor(german_fct_train$Class, levels = c("1" , "0")) 

ggplot(german_fct_train, aes(F_Credit_history, F_Status_of_existing_account)) + 
    geom_jitter(aes(color = Class), size = 3, alpha = 0.5) + theme_economist() + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) + ggtitle("Status of existing checking account 
    and Credit History by Class") + 
    xlab("Credit History") + ylab("Status of existing account") + 
    labs(fill="Class") + 
    scale_fill_manual(limits= c("1", "0"), labels = c("Bad Customers" , "Good Customers"), values = c("red", 'blue')) 

enter image description here

あなたのアドバイスが理解されるであろう。

+0

代わりに 'scale_colour_manual'を試してみてください – bouncyball

答えて

0

例では、Classをggplotの外に因数分解して、scale_fill_manualを適用して、問題の原因となっている可能性が最も高いラベルを追加することをおすすめします。ここでmtcars

data("mtcars") 
library(ggplot) 
ggplot(mtcars, aes(factor(carb), factor(gear))) + 
    geom_jitter(aes(color = factor(gear)), size = 3, alpha = 0.5) + 
    scale_fill_manual(values = c("red", 'blue', 'darkgoldenrod'))+ 
    xlab("Credit History") + ylab("Status of existing account") + 
    labs(x="Credit History", y="Status of existing account", 
     title = "Status of existing checking account and Credit History by Class") + 
    theme_light() + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

も、私はまた、代わりにxlablabsコールを使用することをお勧めしylab、およびggtitleうと例です。最後に、ggplotはコール終了時にが好きな傾向があり、これによってもいくつかのエラーが発生する可能性があります。

関連する問題