Data and Previous Content
This question is a continuation of a
Instead of coloring a specific regression line, now I want to add a direct label to the plot window like above. I know that by faceting the data, we can achieve this with a legend, coloring the lines, etc. We can even manually add an annotation by selecting the x and y coordinates with annotate
or geom_text
.
But I want something that doesn't require a legend or manually figuring out where the exact geom coordinates are. Is there a way to simply add the label to a regression line within the plot window similar to other aes
functions? This is the base plot I have so far, with the label now removed and regression lines colored:
ggplot(slack.work,
aes(x=Coffee_Cups,
y=Mins_Work,
color=Month_Name))
geom_point(alpha = .4)
geom_smooth(method = "lm",
se = F)
scale_colour_viridis_d()
theme_bw()
labs(title = "Coffee Cups x Minutes of Productivity",
subtitle = "Pearson r = .30, p < .001",
x="Cups of Coffee",
y="Minutes of Work",
color="Month")
theme(plot.title = element_text(face = "bold",
size = 15,
family = "mono"),
plot.subtitle = element_text(face = "italic"),
legend.position = "none")
Currently, it looks like this:
But I would like for it to look something like this:
CodePudding user response: