我在ggplot中有一個繪圖,其中有4個單獨的行,我已經添加了一個單獨的geom_line()參數。我想添加圖例,但scale_colour_manual在這種情況下不起作用。當我單獨添加變量時,添加圖例的正確方法是什麼?當手動添加行時,將圖例添加到ggplot
這裏是我的代碼:
ggplot(proba[108:140,], aes(c,four)) +
geom_line(linetype=1, size=0.3) +
scale_x_continuous(breaks=seq(110,140,5)) +
theme_bw() +
theme(axis.line = element_line(colour = "black", size=0.25),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank()) +
theme(axis.text.x = element_text(angle = 0, hjust = +0.5, size=6,color="black")) +
theme(axis.text.y = element_text(angle = 0, hjust = -100, size=6, color="black")) +
theme(axis.ticks=element_line(colour="black",size=0.25)) +
xlab("\nTime-steps") +
ylab("Proportion correct\n") +
theme(axis.text=element_text(size=8),axis.title=element_text(size=8)) +
geom_line(aes(c,three), size=0.2, linetype=2) +
geom_line(aes(c,one),linetype=3, size=0.8, colour="darkgrey") +
geom_line(aes(c,two), linetype=1, size=0.8, colour="darkgrey")
你能發佈你的代碼嗎?在調用'aes'時設置'color =「Line Name」'應該可以。 – Peyton
我已經有了一個參數的顏色,但它不會將其顯示爲圖例。我發佈了我的代碼。 – user1723765
將'color'參數放在'aes'中,而不是將其設置爲顏色名稱,將其設置爲您想要在圖例中出現的名稱。然後使用'scale_color_manual'將該名稱映射到所需的顏色。 – Peyton