我環顧四周,但我似乎無法找到解決方案。我在ggplot2中使用了geom_point和geom_hline,並且都獲得了令人滿意的傳說。然而,我在圖中有一條黑線和一條藍線,但在圖例中它們都是黑色的 - 我怎樣才能在傳說中糾正這種錯誤是正確的顏色?geom_hline的顏色在圖例中不正確[ggplot2]
mcgc <- ggplot(sam, aes(x = Person,y = mm, colour = X)) +
geom_point(size = 0.75) +
scale_colour_gradient2(high="red", mid="green", limits=c(0,1), guide = "colourbar") +
geom_hline(aes(yintercept = mad, linetype = "mad"), colour = "blue", size=0.75, show_guide = TRUE) +
geom_hline(aes(yintercept = mmad, linetype = "mmad"), colour = "black", size=0.75, show_guide = TRUE) +
facet_wrap(~ Plan, scales = "free", ncol = 4) +
scale_linetype_manual(name = "Plan of Health Care", values = c("mad" = 1, "mmad" = 1),guide = "legend")
我敢肯定,我已經在這裏寫東西......只是不知道在哪裏(是新來ggplot)
數據:
Plan Person X mm mad mmad
1 1 95 0.323000 0.400303 0.12
1 2 275 0.341818 0.400303 0.12
1 3 2 0.618000 0.400303 0.12
1 4 75 0.320000 0.400303 0.12
1 5 13 0.399000 0.400303 0.12
1 6 20 0.400000 0.400303 0.12
2 1 219 0.393000 0.353350 0.45
2 2 50 0.060000 0.353350 0.45
2 3 213 0.390000 0.353350 0.45
2 4 204 0.496100 0.353350 0.45
2 5 19 0.393000 0.353350 0.45
2 6 201 0.388000 0.353350 0.45
計劃上升到40,但我只包含一小段數據...
更新:對於那些可能有所幫助 - 我的代碼來繪製數據是錯誤的。我已經更新了這個。
你更可能通過編輯的問題,以獲得幫助,如果你做這個重複的例子,包括您的數據(例如,'sam',和值'mad'和' mmad')。 – jlhoward
更新我的問題以包含數據。 – user2726449