I have measured data in the form of:
Time(sec);Stress(MPa);ax-strain;rad-strain
from a compression test.
The plot looks like a zig-zag line:
now I want to generate data for a smooth plot to use in a next step.
My first idea was to use moving average to smooth the curves, but unfortunately there are some “spikes” which should not be smoothed at all (in the attached picture the “spikes” are not shown).
A clue might be here: How to make multiple smooth curves in one plot in R (with these data)?, but unfortunately I can’t get that code to work.
I guess I need to find an algorithm to select the “spikes” and do the moving average for the rest of the data around.
I’m using R 4.3.3
The whole diagram looks like:
The smoothing script i found is:
# Data munging
library(tidyr)
library(tidyverse)
library (ggplot2)
library(dplyr)
tribble(~"Km1",~"Speed1",~"Km2",~"Speed2",~"Km3",~"Speed3",
10,32,8,64,5,34,
20,63,15,34,15,23,
30,45,26,46,25,55,
40,45,37,75,35,64,
50,1,50,2,50,3) %>%
tidyr::pivot_longer(cols = everything(),names_to = "Name",values_to = "Values") %>%
dplyr::mutate(Car = str_extract(Name,"\d") %>% str_c("Car ",.),
Name = str_replace(Name,"\d","")) %>%
dplyr::group_by(Car,Name) %>%
dplyr::mutate(Values = str_c(Values,collapse = ",")) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(id_cols = Car,names_from = Name,values_from = Values) %>%
tidyr::separate_rows(Km, Speed) %>%
dplyr::mutate(Km = as.numeric(Km),
Speed = as.numeric(Speed))
# Data plotting
ggplot(aes(Km,Speed,color = Car)) +
geom_point() +
stat_smooth()
The data table is quite big to be posted here, please reach out directly to me for the data.