Plotting timeseries data with missing values

Hello everybody,

My apologies, but I need your help an other once. Thanks for your help, and I hope I will understandable (I'm French PhD Student).

I give you my R code and I explain my problem :

plot(s9g$pupil_timestamp_secondes , s9g$diameter_3d_c , type='l' , xlab="Secondes" , ylab="Diamètre pupille (milimètres)" , col="royalblue3" , main="Premier regard sur les données \n pour ajuster datas aberrantes COUCHE DEBOUT - GAUCHE")

This first part is OK for me and it works. However, in my dataframe (y axes), I have missing value (NA).

My problem : When I have a missing value, my curve is cut (I try since yesterday to find differents possibilities to resolve my problem with "na.kalma" or others things but it doesn't works).

My aim : I want to connect/link these parts of my curve. And if it's possible with a specific color or with a dotted line.

Thank you for your help.

Yours sincerely,

GIOVANNANGELI Cyril

Hello.
Thanks for providing code , but you could take further steps to make it more convenient for other forum users to help you.

Share some representative data that will enable your code to run and show the problematic behaviour.

You might use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.

Reprex Guide

Ok, no problem, so I give you

  • a picture of my graphic :

  • My R code
plot(s9g_copy$numeroimage , s9g_copy$diameter_3d_c , type='l' , xlab="Numeroimage" , ylab="Diamètre" , col="royalblue3" , main="Graphique 1")
  • A link on wetransfert in order to download the dataframe

Yours sincerely,

GIOVANNANGELI Cyril

I would encourage you share example data in the recommended way, this will increase your chance of gaining support.

Perhaps something like

notNA <- which((!is.na(x)) & (!is.na(y)))
plot(x[notNA], y[notNA])

I think I would do something like loess smoothing of the curve, and pick values from the loess to use in place of the NA's in the original

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Hi Community !

I think I found the answer :

  • I kept my normal datas with the blanks parts on my curve
  • I applied a filter on my datas in order to have an other curve without blanks (below, I propose 2 filters, you need to choose the better for you) :
library(dplR)

x <- na.omit(PLR2[, 6])

#low-pass filter -- note freq is passed in
bSm <- pass.filt(x, W=0.05, type="low", method="Butterworth")
cSm <- pass.filt(x, W=0.05, type="low", method="ChebyshevI")
plot(x, type="l", col="green")
lines(bSm, col="red")
lines(cSm, col="blue")

So with these solutions I have my datas with blanks parts and an other curve with a filter curve without blank parts.

Have a nice day.

Yours sincerely