Reputation: 691
I would like to add one title to my legend. The argument "fill" and "color" have the same variable : varC (14 factors). I try to do this with :
g.mean <- ggplot(df,aes(x = as.numeric(xx),y=yy,color=varc)) +
geom_line() +
geom_ribbon(aes(ymin=Born_Inf, ymax=Born_Sup, fill=varc), alpha=0.1) +
guides(color= guide_legend("My title for line"),fill=guide_legend("My title for ribbon"))
Upvotes: 0
Views: 96
Reputation: 1106
Remove guides
and try one of the following. The reason I give two possible answers is because I cannot be 100% sure exactly which will work without seeing a sample of your data. If varc
is a factor
or character
the second one should work, if it is numeric
the first one should work.
1.
ggplot(df,aes(x = as.numeric(xx),y=yy,color=varc)) +
geom_line() +
geom_ribbon(aes(ymin=Born_Inf, ymax=Born_Sup, fill=varc), alpha=0.1) +
scale_color_continuous(name = "My title for line") +
scale_fill_continuous(name = "My title for ribbon")
2.
ggplot(df,aes(x = as.numeric(xx),y=yy,color=varc)) +
geom_line() +
geom_ribbon(aes(ymin=Born_Inf, ymax=Born_Sup, fill=varc), alpha=0.1) +
scale_color_discrete(name = "My title for line") +
scale_fill_discrete(name = "My title for ribbon")
Upvotes: 2