why using ggscatter lead to fund( left to right ) error?

Viewed 36

applying ggscatter on X & y both are double

 ggscatter(merged_clean, x = "Doctors", y = "val",
        add = "reg.line", conf.int = TRUE, 
        cor.coef = TRUE, cor.method = "pearson",
        xlab =  "Estimated Doctors Density per 1000", ylab = "HIV Mortality rate per 100 0000")

leading to: Error in FUN(left, right) : operations are possible only for numeric, logical or complex types

1 Answers

I do not think there is anything obviously wrong with your code so I would guess the problem was with merged_clean but your example would be better if it could be run on its own, including the data. For me

library(tidyverse)
library(ggpubr)
merged_clean <- tibble(
   Doctors = c(1, 2, 3, 4, 5.5),
   val =  c(2.5, 3, 3, 4, 3.5))
ggscatter(merged_clean, x = "Doctors", y = "val",
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "pearson",
          xlab =  "Estimated Doctors Density per 1000", 
          ylab = "HIV Mortality rate per 100 0000")

produces

enter image description here

and this is the sort of thing I would expect

Related