Hello everone,
How can I change the scientific notation in R label using stat_cor, it's a request from the paper revisor and I can´t figure how to do so, and also I need to change the size of only one word in the label strip text.
Can someone help me please?
Here is a data for example:
library("tidyverse")
# Create example data -----------------------------------------------------
n <- 91
set.seed(232153)
my_data <- tibble(
x1 = as.integer(seq(1940,2030,1)),
x2 = as.integer(seq(1,91)),
g1 = sample(LETTERS[1:3], size = n, replace = TRUE),
g2 = sample(LETTERS[4:6], size = n, replace = TRUE),
)
# Augment data ------------------------------------------------------------
my_data <- my_data %>%
mutate(x1_A_D = case_when(g1 == "A" & g2 == "D" ~ x1),
x2_A_D = case_when(!is.na(x1_A_D) ~ x2))
# Visualise ---------------------------------------------------------------
my_data %>%
ggplot(aes(x = x1, y = x2)) +
geom_line() +
geom_smooth(aes(x = x1_A_D, y = x2_A_D),
method = "lm", linetype = "dashed") +
stat_regline_equation(aes(x = x1, y = x2), label.x=1995, label.y=75, size = 2) +
stat_cor(aes(x = x1, y = x2, label = ..p.label..),
label.y= Inf, label.x = Inf, vjust = 3.3, hjust = 1.8, size = 2) +
facet_grid(vars(g2), vars(g1), scales = "free_y", switch = "y")