I have a question about how to change the legend text, I tried a few answers from this site and non of them worked. Here is the example code:
counts <- c(18,17,15,20,10,20,25,13,12)
time <- c(1, 1.3, 1.11, 1, 1, 1, 1, 1.3, 1.1)
sex <- c("m","f","m","f","m","f","m","f","m")
print(myDF <- data.frame(sex, counts, time))
ggplot(myDF, aes(counts, time, color=sex)) +
geom_point(size = 3)+geom_smooth(method="lm", se=F) +
ggtitle("Long-Term Gain in Speech Rate")+
xlab("Baseline Speech Rate") +
ylab("Mean Speech Rate Gain")+
theme(legend.position = "bottom")
The result is:
As some answers suggested to use the scale_fill_manual() or scale_fill_discrete(). I tried these solutions but none of them changed the legend text, such as the code below:
counts <- c(18,17,15,20,10,20,25,13,12)
time <- c(1, 1.3, 1.11, 1, 1, 1, 1, 1.3, 1.1)
sex <- c("m","f","m","f","m","f","m","f","m")
print(myDF <- data.frame(sex, counts, time))
ggplot(myDF, aes(counts, time, color=sex)) +
geom_point(size = 3)+geom_smooth(method="lm", se=F) +
ggtitle("Long-Term Gain in Speech Rate")+
xlab("Baseline Speech Rate") +
ylab("Mean Speech Rate Gain")+
theme(legend.position = "bottom")+
scale_fill_discrete("", labels=c('women', 'men'))
Any suggestions?
color
aesthetic, so you should usescale_color_discrete