path <- paste0(tempdir(),"rec_1.dat")
download.file("https://physionet.org/files/ecgiddb/1.0.0/Person_01/rec_1.dat?download",path)
ecg <- readBin(path,integer(),500*30)
peaks <- detect_rpeaks(ecg, sRate = 500)
unlink(path)
print(peaks)
ecg.df <- data.frame(ECG = ecg,Seconds = c(1:length(ecg))/500)
library(ggplot2)
ggplot(ecg.df,aes(x = Seconds,y = ECG)) +
geom_line() + theme_bw() +
geom_vline(data.frame(p = peaks),mapping = aes(xintercept = p), linetype="dashed",color = "red")
Run the code above in your browser using DataLab