0
我正嘗試創建條形圖,但I'm得到一個錯誤,如:如何在同一ggplot條形圖中設置scale_fill_brewer和scale_fill_discrete?
量表「補」已經存在。爲「填充」添加另一個比例, 將取代現有比例。
我發現問題是因爲試圖使用兩個scale_fill函數。如果我刪除其中的一個(scale_fill_brewer或scale_fill_discrete),它將起作用。
ggplot(df_postgres, aes(x=as.factor(language), y=total/1000, fill=type)) +
geom_bar(stat='identity', color = 'black')+
geom_text(mapping=aes(label=ifelse(type=='A', (paste(as.character(floor(total/1000)),'K')), '')), vjust=-0.7,color='black')+
scale_x_discrete(name="Language")+
scale_y_continuous(name="Repos (thousands)")+
scale_fill_brewer(palette='Pastel1')+
scale_fill_discrete(name="Proportion",labels=c("Language","Others"))
我的問題是:如何設置離散選項和漂亮的調色板選項? 我是R的新手,但無法找到對這個特定錯誤的迴應。
只是將'scale_fill_discrete'的名稱和標籤參數賦給'scale_fill_brewer'。他們將通過內部傳遞 - 通過'...' –
理查德!你應該寫一個答案,以便我可以接受。這很有趣,我已經嘗試了反過來,給參數scale_fill_discrete :) – atorres