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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -