I have a graph with several geom_point and one stat_function in ggplot2 . Is there a way to show one legend?
df <- data.frame("x"=c(1:5), "a"=c(1,2,3,3,3), "b"=c(1,1.1,1.3,1.5,1.5)) df <- melt(df, "x") p <- ggplot(df, aes(x=x, y=value)) + geom_point(aes(colour=variable, shape=variable)) + stat_function(aes(colour="log2(x)"), fun=log2)

I want to have one legend with a blue line and two color shapes. I tried
scale_colour_discrete(name="legend", breaks=c("a", "b", "log2(x)")) + scale_shape_discrete(name="legend", breaks=c("a", "b"))
but it does not work. Is there a way to do this automatically or manually?
Thanks in advance.
source share