How do you remove certain regression lines in ggplot2 but keep others using the stat_smooth or geom_smooth functions?
I am plotting length ~ weight relationships for fish, comparing between lakes, years, species and parasitism.
I am able to plot regression lines for everything, for example Parasitized vs Non Parasitized, however if one group say for example Parasitized only has 2 points, a regression line is still made for it, as with all the others that have 3 or more points.
My question is how do you plot your data to create regression lines for data that has 3 or more points but at the same time doesn't create regression lines for data that has only two points?
I have included the data and a sample graph with the issue:

> str(B2_2016)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 8 obs. of 16 variables:
$ Year : num 2016 2016 2016 2016 2016 ...
$ Sample ID : chr "b2-ss-01" "b2-ss-03" "b2-ss-05" "b2-ss-06" ...
$ Species : chr "P. pungitius" "P. pungitius" "P. pungitius" "P. pungitius" ...
$ Total Wt (g) : num 0.0643 0.923 0.0807 0.1435 0.0292 ...
$ Total Length (cm): num 2.4 5.2 2.7 3 1.9 2.3 3.6 5.7
$ Sex : num 0 0 0 0 0 0 1 1
$ Age : chr "-" "3" "-" "-" ...
$ Liver Wt (g) : chr "-" "4.02E-2" "-" "-" ...
$ Gonad Wt (g) : chr "-" "-" "-" "-" ...
$ Condition (K) : num 0.465 0.656 0.41 0.531 0.426 ...
$ HSI : chr "-" "4.3553629469122424" "-" "-" ...
$ GSI : chr "-" "-" "-" "-" ...
$ Parasites : num 0 0 0 0 0 0 1 1
$ P Weight : num NA NA NA NA NA ...
$ Gut Contents : chr "-" "Y" "-" "-" ...
$ S.I. : chr "-" "Y" "-" "-" ...
x and y axes are log10
Year = c(2016, 2016, 2016, 2016, 2016, 2016, 2016, 2016),
`Sample ID` = c("b2-ss-01", "b2-ss-03", "b2-ss-05", "b2-ss-06", "b2-ss-07", "b2-ss-08", "b2-ss-02", "b2-ss-04"),
Species = c("P. pungitius", "P. pungitius", "P. pungitius", "P. pungitius", "P. pungitius", "P. pungitius", "P. pungitius", "P. pungitius"),
`Total Wt (g)` = c(0.0643, 0.923, 0.0807, 0.1435, 0.0292, 0.0689, 0.13, 1.1902),
`Total Length (cm)` = c(2.4, 5.2, 2.7, 3, 1.9, 2.3, 3.6, 5.7),
Sex = c(0, 0, 0, 0, 0, 0, 1, 1),
Age = c("-", "3", "-", "-", "-", "-", "2", "3.3"),
`Liver Wt (g)` = c("- ","4.02E-2", "-", "-", "-", "-", "8.9999999999999993E-3", "3.3799999999999997E-2"),
`Gonad Wt (g)` = c("-", "-", "-", "-", "-", "-", "2.3999999999999998E-3", "4.5999999999999999E-3"),
`Condition (K)` = c(0.465133101851852, 0.656434911242603, 0.409998475842097, 0.531481481481481, 0.425718034698936, 0.56628585518205, 0.27863511659808, 0.642680878866912),
HSI = c("-", "4.3553629469122424", "-", "-", "-", "-", "6.9230769230769225", "2.8398588472525623"),
GSI = c("-", "-", "-", "-", "-", "-", "1.846153846153846", "0.38648966560241976"),
Parasites = c(0, 0, 0, 0, 0, 0, 1, 1),
`P Weight` = c(NA, NA, NA, NA, NA, NA, 0.1918, 0.0586),
`Gut Contents` = c("-", "Y", "-", "-", "-", "-", "Y", "N"),
S.I. = c("-", "Y", "-", "-", "-", "-", "Y", "Y")),
.Names = c("Year", "Sample ID", "Species", "Total Wt (g)",
"Total Length (cm)", "Sex", "Age", "Liver Wt (g)", "Gonad Wt (g)",
"Condition (K)", "HSI", "GSI", "Parasites", "P Weight", "Gut Contents",
"S.I."), row.names = c(NA, -8L), class = c("tbl_df", "tbl", "data.frame"))
So I am getting these errors...
attach(All_Years_All_Lakes_All_Species)
> SticklesDataF = group_by(All_Years_All_Lakes_All_Species, Species, Year, Parasites, Lake) %>% mutate(n = n()), LogLength = log('Total Length (cm)'), LogWeight = log('Total Wt (g)'))
Error: unexpected ',' in "SticklesDataF = group_by(All_Years_All_Lakes_All_Species, Species, Year, Parasites, Lake) %>% mutate(n = n()),"

dplyrordata.tableor whatever to flag groups with 3 or less points, subset the data for thegeom_smoothbased on that flag. - Gregor Thomaslibrary(tidyverse); ggplot(mtcars, aes(hp, mpg, color = factor(cyl))) + geom_point() + geom_smooth(data = mtcars %>% group_by(cyl) %>% filter(n() > 10), method = 'lm')- alistaire