Sorry, still learning... Heres my reprex:
df <- data.frame(
year = c(2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L),
total_length = c(68, 35, 37, 36, 37.5, 41, 36, 51, 49, 68, 54, 53, 49, 51,
50, 59, 55),
age = c(4, 1, 1, 1, 1, 2, 2, 2, 2, 4, 3, 3, 3, 3, 4, 4, 3),
parasites = c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.4.4
library(dplyr)
#> Warning: package 'dplyr' was built under R version 3.4.4
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df %>%
group_by(parasites) %>%
group_by(age) %>%
mutate(mean_length = mean(total_length)) %>%
ggplot(aes(x = age, y = total_length)) +
geom_point(aes(shape = as.factor(parasites), size = 2)) +
geom_smooth(aes(y = mean_length), method = "loess") +
geom_point(aes(y = mean_length), color = "black") +
theme_bw()
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : pseudoinverse used at 0.985
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 2.015
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 4.2401e-017
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 4.0602
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
#> at 0.985
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
#> 2.015
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : reciprocal
#> condition number 4.2401e-017
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : There are other
#> near singularities as well. 4.0602
Created on 2019-02-22 by the reprex package (v0.2.1)
My data set will be bigger than this and what I am trying to do is plot on the same graph, Parasitized and Non Parasitized Points for each age class, with each having there respective mean length for each curve. Also how would I use jitter to ensure points are not on top of each other?
Thanks