問題
如何爲每個方面使用不同的調色板?理想情況下,我希望將灰色的通用圖例作爲參考。ggplot中facet的單獨調色板facet_grid
我正在使用ggplot的facet_grid進行可視化工作。佈局很好,但我想爲網格中的每一行使用不同的調色板。我的目標是對每個調色板使用類似陰影的漸變,然後用灰度圖例將它們連接在一起。我想這樣做是爲了在一組更大的圖形中保持內部顏色編碼的一致性。能夠仍然使用facet_grid而不是使用grobs(我並不太熟悉),這將會令人驚訝。
我已經包括一個例子來使用鑽石數據集和任意分組來近似我的數據的樣子。
data(diamonds)
diamonds$arbitrary = sample(c("A", "B", "C"), length(diamonds$cut), replace = TRUE)
blues = brewer.pal(name="Blues", n=3)
greens = brewer.pal(name="Greens", n=3)
oranges = brewer.pal(name="Oranges", n=3)
purples = brewer.pal(name="Purples", n=3)
ggplot(diamonds) +
geom_bar(aes(x = clarity, stat = "bin", fill = arbitrary, group = arbitrary)) +
facet_grid(cut~.) +
# Here I assign one palette... is this where I could also
# designate the other palettes?
scale_fill_manual(values = blues)
謝謝!
GGPLOT2不支持單獨的調色板刻面。 – Roland
我只是想過使用一個與這個面相吻合然後對傳說進行硬編碼的ghost變量,但我不得不燉它。 – Nancy