我想为ggplot制作一个完全定制的图例。出于MWE之外的复杂原因,我不不想在各种color
参数中指定aes
。
这是我要工作的一个示例:
p = ggplot() +
# First plot some data from one set
geom_point(aes(x = rnorm(10), y = rnorm(10)), col = "blue") +
# Then plot some data from another set
geom_point(aes(x = rnorm(10) + 1, y = rnorm(10) + 1), col = "orange") +
# Just to make the plot mildly cleaner
labs(x = "X", y = "Y") +
# Now want to manually come up with my own legend
# However ggplot seems to ignore this
scale_colour_manual(name = "Group",
values = c("Group 1" = "blue", "Group 2" = "orange"))
# Printing the plot
p
但是,如下面所示,结果图将忽略我的scale_colour_manual
调用:
如何独立强制自定义图例?