我试图让图例中的文字与ggplot中的线条颜色相同。说女性的行为绿色,男性为蓝色,然后文本说女性为绿色,男性为蓝色。
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"))