r - How to create legend text elements being different colours in a ggplot? -
i'm trying made text in legend same colour line in ggplot. line female green , male blue text saying female green , male blue.
df1 <- data.frame( sex = factor(c("female","female","male","male")), time = factor(c("lunch","dinner","lunch","dinner"), levels=c("lunch","dinner")), total_bill = c(13.53, 16.81, 16.24, 17.42)) ggplot(data=df1, aes(x=time, y=total_bill, group=sex, shape=sex, colour=sex)) + geom_line()+ scale_color_manual("sex",values=c("green", "blue"))
test code taken from: http://www.cookbook-r.com/graphs/legends_(ggplot2)/
Comments
Post a Comment