0

Do I need to convert my tibble into a data frame when I call ggscatter?

My code works fine when I convert my tibble to a data frame before calling ggscatter. Is there a way to use the tibble directly in the ggscatter call without needing to convert it first.

library(magrittr) # needs to be run every time you start R and want to use %>%
library(dplyr)    # alternatively, this also loads %>%
library(ggplot2)
library(ggpubr)


data_set <- tibble(
  Unemployment_Rate_Perc = c(4.5,3.8,5.1,4.9,5.4,4.8,5.5,4.3,5.7,4.6),
  Labor_market_stress_index = c(107,107,100,100,80,100,100,93,87,80)
)

cor(data_set$Labor_market_stress_index,data_set$Unemployment_Rate_Perc,method = "pearson")

data_set <- as.data.frame(data_set)

ggscatter(data_set, y = "Labor_market_stress_index", x = "Unemployment_Rate_Perc", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "pearson",
          xlab = "", ylab = "")

When I don't convert the tibble to a data frame I get an error Can not find Y variable... How come?

Michael
  • 59
  • 7
  • If this is reproducible, perhaps this is an [issue for `ggpubr`](https://github.com/kassambara/ggpubr/issues). – r2evans Aug 16 '19 at 16:37
  • It works on my computer. – www Aug 16 '19 at 18:00
  • Have you updated ggpubr recently? It works on my computer, and ggscatter has an internal data check step that automatically converts tibbles to dataframes. – David Klotz Aug 16 '19 at 18:31

0 Answers0