2012-09-08 45 views
2

我使用scale_colour_manual來指定我需要的可能顏色。但是,如果我選擇red,我會得到令人眼花繚亂的紅色,而不是比較溫和的ggplot2默認紅色,如果我首先不使用scale_colour_manual,則會出現這種紅色。訪問ggplot2默認調色板的標籤或常量是什麼?ggplot2使用scale_colour_manual訪問默認顏色?

ggplot(data=df, aes(x=n, y=rt, group=kernel, shape=kernel, colour=kernel)) + 
    geom_point(fill="white", size=3) + geom_line() + xlab("n") + ylab("Runtime (s)") + 
    opts(title=title,plot.title=theme_text(size=font.size)) + 
    scale_colour_manual(values=c("grey30", "red")) + 
    opts(legend.position = c(x_shift,0.87),legend.background=theme_rect(fill = "transparent",colour=NA)) 

請注意,使用'red30'將不起作用,它只適用於灰色由於某種原因我不知道的原因。

+1

嘗試「鮭魚」而不是「紅色」。 –

+1

查看http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette –

回答

4

red30不起作用,因爲沒有隻有30歲的顏色百分比的概念,雖然是具有黑色之間的灰色的方式(即30%陰影的百分之三十的概念白色。)

如果你想要一個非灼熱的紅色與scale_color_manual你需要指定顏色RGB,即。通過使用三個字節來表示十六進制的紅色綠色和藍色。像這樣的東西應該工作

ggplot(data=df, aes(x=n, y=rt, group=kernel, shape=kernel, colour=kernel)) + 
geom_point(fill="white", size=3) + geom_line() + xlab("n") + ylab("Runtime (s)") + 
opts(title=title,plot.title=theme_text(size=font.size)) + 
scale_colour_manual(values=c("grey30", "#EF8A62")) + 
opts(legend.position = c(x_shift,0.87),legend.background=theme_rect(fill = "transparent",colour=NA)) 

如果你不知道如何使用這種顏色編碼的參考this工作。我不知道如何提取ggplot以編程方式使用的顏色,但是您可以隨時將使用標準顏色生成的圖加載到某個圖像編輯器(例如The Gimp)中,並找出確切的顏色代碼。您可以在colorbrewer上找到很好的配色方案,但請注意,ggplot2已經具有以下功能:scale_brewer

+0

找到默認的ggplot顏色,請參閱我上面評論中的鏈接。 –

+0

'rgb'允許透明度值。 –