Hello, I am trying to put regression line equation and R2 on my plot, please let me know if someone know how i can get that.
Here is my code:
library(ggplot2)
df <- read.csv("F:/Chapter6_Files_Figures/scatterplot.csv", stringsAsFactors = F)
colnames(df)[1] = "sample_name"
colnames(df)[2] = "Flavor"
colnames(df)[3] = "JAR"
ggplot(df, aes(x = JAR, y = Flavor)) +
geom_point(color = "#669999") +
geom_smooth(method=lm, linetype = "dashed", color="black") +
coord_cartesian(ylim=c(1, 9)) +
scale_y_continuous(breaks=seq(1, 10, 1))
#> `geom_smooth()` using formula 'y ~ x'
Created on 2020-07-07 by the reprex package (v0.3.0)