我從我的數據(下面的示例)創建ggplot。我想區分哪些數據點屬於哪個PID
。到目前爲止好:改變顏色的調色板中ggplot
violin.murgang <- ggplot(nkv.murgang, aes(x = factor("Murgang"), nkv.murgang$NK)) +
geom_violin(color = "black", fill = "darkorange") +
ggtitle("NKV Murgang - Einfamilienhaus") +
labs(x = "Prozess", y = "Nutzen/Konsten \n Verhälhniss") +
stat_summary(geom = "text", fun.y = quantile,
aes(label=sprintf("%1.1f", ..y..)),
position=position_nudge(x=0.4), size=3) +
theme (legend.position = "none") +
stat_summary(fun.data = give.n, geom = "text", position=position_nudge(x=-0.4)) +
geom_jitter(aes(col = PID), width = 0.35)
violin.murgang
的問題是,所有的NKV
數據點在不同的色調的藍色只顯現。我想有不同的顏色。我曾嘗試添加此:
scale_colour_brewer(palette="Spectral")
其產生錯誤:
Error: Continuous value supplied to discrete scale
我如何能實現具有用於geom_jitter
部分不同的顏色?
什麼原因導致錯誤?
謝謝!
我認爲brewer顏色只適用於離散變量。看看'scale_colour_gradient'和'scale_colour_gradient2'。 –