How can I get my points to connect in a plot and show a trend with NA values in data?

前端 未结 2 1964
逝去的感伤
逝去的感伤 2021-01-28 16:12

I have a basic set of data, where I measure concentration over time for 24 months. Some months have not been sampled, so there are 6 NA values in my list.

2条回答
  •  攒了一身酷
    2021-01-28 16:57

    df <- data.frame(time=c(-1, 0, 1:24),
    pt=c(7.0, 6.9, NA, 5.5, 5, 3, 14, NA, 23, NA, 14.5, 7, 9, NA, 11, 8, 5.2, 5.3, NA, 5, 3, NA, 1.5, NA, NA, 2))
    
    png("test.png")
    plot(pt~time, type="o", data=na.omit(data.frame(df)),
         pch=16, col="blue",
         xlab="Time (months) relative to implant",
         ylab="Concentration (ng/ml)",
         main="Concentration Overtime",
         xlim=c(-1, 24),
         xaxt='n')
    axis(1, at=seq(-1, 24, by=1))
    dev.off()
    

提交回复
热议问题