'Why ggscatter does not work with NA in R?

I am trying to plot a direct correlation between A and B with ggscatter, however, I have many NAs, since the variables were not measured the same day. Therefore, no correlation coefficient appears. Is there any way of "omitting" or ignoring these NAs?

library("ggpubr")

data<- data.frame(
      Days=c(0,2,4,6,7,9,10,13,14,18,22,25,30),
      A=c(NA,678,1698,NA,3484,NA,3322,NA,3776,3279,3182,3438,2689),
      B= c(300,1000,NA,3000,NA,3500,NA,4000,NA,NA,5000,NA,NA))

ggscatter(data, x = "A", y = "B", 
          add = "reg.line", 
          conf.int = TRUE, 
          cor.coef = TRUE, 
          cor.method = "pearson",
          xlab = "A", ylab = "B")

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source