How to connect dots where there are missing values?

后端 未结 4 1647
天涯浪人
天涯浪人 2021-01-04 19:01

lets take this example:

       test=c(1,5,NA,5,4,1,NA,3,3,5,4,2)

      plot(test,type=\"l\")

This will plot test but will not connect the

4条回答
  •  一生所求
    2021-01-04 19:25

    Another way that preserves the missing value in the same spots

    data=data.frame(x=1:12,y=test)
    plot(data)
    lines(data)
    lines(na.omit(data),col=2)
    

    Or in ggplot2

    ggplot(data,aes(x,y))+geom_point()+geom_line(data=na.omit(data))
    

提交回复
热议问题