first timer here! I have a data frame regarding Fe and Cr concentration in different soil depths. I want to plot all the data, however I want to create a linear model with only the data from 3 different depths in the same plot. The variable 'depth' is a factor. The other two are numeric.
I tried using subset
, but then - apparently - I can only create a lm
with only one subset. filter
didn't work either, nor []
.
When I tried this:
seq15 %>% filter(depth == "0-3", depth == "3-5", depth == "5-10") %>%
ggplot(aes(Fe, Cr, color=depth)) + geom_point()
The graph came out blank.
When I tried this:
seq15 %>% ggplot(aes(Fe, Cr, color=depth)) +
geom_point() + geom_smooth(data = subset(seq15, depth == "0-3" & depth == "3-5" & depth == "5-10"), method = lm, se = FALSE)
All the data is plotted, but there's no lm
.
The head is as follow:
head(as_tibble(seq15))
# A tibble: 6 x 9
points depth Cr Cu Fe Mn Ni Pb Zn
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 CAPA 0-3 50.8 17.7 48291 412. 14.2 18.3 32.8
2 P3 0-3 0-3 82.3 26.3 59696 1152 34.8 26 74.5
3 P3 3-5 3-5 19.5 1.81 21944 201. 4.61 2.66 12.1
4 P3 5-10 5-10 19.2 2.09 28234 213. 4.43 3.05 14.3
5 P3 20-25 20-25 14.1 1.53 8751 185. 4.82 1.86 7.66
6 P4 Borda Lagoa ~ 0-3 60.4 18.7 42646 336 25 17 65