2013-04-12 153 views
18

我正在使用ggplot進行散點圖。我想有一個特定的顏色和填充點(在plot,colour="blue", fill="cyan4",例如),但我無法找到。我有這一點是:ggplot中的geom_point(scale_colour_manual)中的填充和邊框顏色

ggplot(df, aes(own,method)) + 
    panel.configuration + 
    scale_shape_identity() + #to use the 'plot' shape format. 
    geom_point(aes(color = factor(label)), position = "jitter",size=3) + 

(在以前geom_point我嘗試添加shape=21我會在plot已完成)

scale_colour_manual(values=c("A"="chocolate3","B"="cyan4")) + 
    scale_fill_manual(values=c("A"="green", "B"="red")) + #DOES NOTHING... 
    xlim(7,47) + ylim(7,47)+ ... etc. 

這就是我得到沒有「形狀= 21」

enter image description here

這是我添加「形狀= 21」時得到的結果。在兩種情況下它忽略scale_fill enter image description here

我還嘗試添加在geom_point fill=c("blue","red"),但ř抱怨:「錯誤:集美學不相容長度:形狀,大小,填充」。

有關如何獲取它的任何建議? scale_fill在我的代碼中出了什麼問題?

非常感謝!

數據(DF)的樣子:

21 15 A 
24 16 A 
24 17 A 
28 14 A 
24 15 A 
22 15 A 
20 18 A 
24 18 A 
34 9 B 
38 12 B 
41 19 B 
42 13 B 
36 12 B 
40 17 B 
41 14 B 
37 12 B 
40 13 B 
37 15 B 
35 15 B 

回答

38

你將不得不使用形狀從21 to 25。這些都是有colourfill性質的:如果你想爲colour不同的顏色以及

ggplot(df, aes(own, method)) + 
    geom_point(colour="white", shape=21, size = 4, 
    aes(fill = factor(label))) + 
    scale_fill_manual(values=c("blue", "cyan4")) 

,則:

+1

謝謝阿倫。你的建議完美地工作,但它填補了相同顏色的所有點。是否有可能爲'plot'中的每個指定一個特定的顏色?我會編輯它以提供數據。 – PGreen

+1

是的。有可能的。我只是在尋找一個數據來創建劇情.. :) – Arun

+1

@PGreen,試試這個編輯。如果你在'aes(。)'(編輯)中插入'colour',你可以用'scale_colour_manual(values = ...)'來做'colour'。 – Arun

相關問題