3 回答

TA貢獻1155條經驗 獲得超0個贊
前幾天我遇到了這個問題。圖例中的R Cookbook部分說明:
如果同時使用顏色和形狀,則都需要為其指定比例尺規格。否則,將有兩個兩個單獨的圖例。
在您的情況下,您需要shape和的規格linetype。
編輯
使用相同的數據創建形狀顏色和線條非常重要,我通過直接定義列來組合了您的交互階段。而不是scale_linetype_discrete創造傳奇,我用scale_linetype_manual指定的值,因為它們將在四個不同的值,默認情況下。
如果您想要所有可能的形狀和線型的詳細布局,請訪問R Graphics網站以查看所有數字標識符:
df.merged$int <- paste(df.merged$Type, df.merged$Method, sep=".")
ggplot(df.merged, aes(x, y, colour = int, linetype=int, shape=int)) +
geom_line() +
geom_point() +
scale_colour_discrete("") +
scale_linetype_manual("", values=c(1,2,1,2)) +
scale_shape_manual("", values=c(17,17,16,16))

TA貢獻1790條經驗 獲得超9個贊
labs()對于定義幾何圖形外觀的所有美學使用并設置相同的值。
library('ggplot2')
ggplot(iris) +
aes(x = Sepal.Length, y = Sepal.Width,
color = Species, linetype = Species, shape = Species) +
geom_line() +
geom_point() +
labs(color = "Guide name", linetype = "Guide name", shape = "Guide name")
- 3 回答
- 0 關注
- 2786 瀏覽
添加回答
舉報