You could just drop the NA values on the fly right before plotting using `df %>% drop_na()` as the `data` argument in your `ggplot` call:
```
library(ggplot2)
library(dplyr)
library(tidyr)
ggplot(data=df %>% drop_na(), aes(x=as.numeric(day), y=mean, fill=treatment, shape=treatment, color=treatment)) +
geom_errorbar(aes(ymin=mean-std_error, ymax=mean+std_error),
position=position_dodge(0.7), width=3, color="grey35") +
geom_line(aes(color=treatment), size=0.5) +
geom_point(size=5, stroke=1, color="white") +
scale_shape_manual(values=c(21,22,24)) +
scale_fill_manual(values=c("red","grey55", "grey15")) +
scale_color_manual(values=c("red","grey55", "grey15")) +
scale_x_continuous(breaks=seq(0,50,10),limits=c(0,50)) +
scale_y_continuous(breaks=seq(0,50,10),limits=c(0,50)) +
theme_classic(base_size=20, base_family="serif") +
theme(legend.position=c(0.15,0.85),
legend.title=element_blank(),
legend.key=element_rect(color="white", fill="white"),
legend.text=element_text(family="serif", face="plain",
size=13, color= "Black"),
legend.background=element_rect(fill=alpha(0.5)),
axis.line=element_line(linewidth=0.5, colour="black"))+
windows(width=5, height=5.5)
```
You could also use a `gam` in `geom_smooth()` with `k` equal to the number of points in each group (13 in this case).
``` r
library(ggplot2)
ggplot(data=df, aes(x=time, y=Radiation)) +
geom_smooth(aes(color=treatment, group=treatment), method="gam", formula = y~ s(x, k=13)) +
geom_point(aes(shape=treatment, fill=treatment), color="black", size=2) +
scale_shape_manual(values= c(21,22)) +
scale_fill_manual(values=c("coral4","grey65"))+
scale_color_manual(values=c("coral4","grey65"))+
scale_x_datetime(date_breaks = "2 hour", date_labels = "%H:%M") +
scale_y_continuous(breaks=seq(0,2500,500), limits = c(0,2500)) +
theme_classic(base_size=18, base_family="serif")+
theme(legend.position=c(0.5,0.9),
legend.title=element_blank(),
legend.key=element_rect(color="white", fill="white"),
legend.text=element_text(family="serif", face="plain",
size=15, color= "Black"),
legend.background=element_rect(fill="white"),
axis.line=element_line(linewidth=0.5, colour="black"))
```
<!-- -->
<sup>Created on 2024-02-29 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>