我有一個在直方圖上疊加了幾個觀測值的圖。觀察結果按順序收集,我需要觀察它們收集的順序。使用scale_colour_brewer
很簡單。問題是,順序brewer調色板的最大長度是9.我有多達20個觀察的例子,我不知道如何使用內插顏色。以下是一些用少於10分表示我所需輸出的代碼。插入一個連續的brewer調色板作爲ggplot2的圖例
# Setting this to be > 9 will cause a warning and not produce the desired result.
observations = 9
subset <-1:observations
res = data.frame(x_data = rnorm(5000),TestID=1:5000)
ggplot(res,aes(x=x_data)) +
stat_bin(aes(y=..density..))+
stat_density(colour="blue", fill=NA)+
geom_point(data = res[res$TestID %in% subset,],
aes(x = x_data,
y = 0,
colour = as.factor(res$TestID[res$TestID %in% subset])
),
size = 5) +scale_colour_brewer("Fancy title", type="seq", palette='Reds')
我知道,隨着觀測數量變大,這個圖將變得難以閱讀。但是,我相信有多達20種顏色,應該可以在我的應用程序中解釋結果。
您將需要使用'scale_colour_gradient2'或使用'scale_colour_manual'滾動自己的色階。啤酒調色板不會超過9類(正確的)。 – joran