When I made a plot using geom_point() and geom_line(), a few values in the middle didn’t appear and I can’t figure out why.
I have a dataframe with 3 columns (K_value, CV_error, and Run), where K_value is categorical.
I wanted to plot the mean rate of change across K_value, like so:
df %>%
mutate(rate = CV_error - lag(CV_error)) %>%
mutate(sd = sd(rate),
.by=K_value) %>%
mutate(meanrate = mean(rate),
.by=K_value) %>%
ggplot(aes(x=K_value, y=meanrate)) +
geom_point() +
geom_errorbar(aes(ymin=meanrate-sd, ymax=meanrate+sd), width=0.2) +
geom_line(aes(group=1))
This yields:
Any idea why the data for K=10 is not appearing? The data for K=10 is there in the original df, and when I plot other things (e.g., the mean of CV_error) it shows up fine. I’m wondering if it has something to do with lag()
. Am I using it incorrectly?