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?