# generate artificial data
set.seed(4321)
x <- (1:100) / 10
y <- x + rnorm(length(x))
my.data <- data.frame(x = x,
y = y,
y.desc = - y,
group = c("A", "B"))
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation()
ggplot(my.data, aes(x, y.desc)) +
geom_point() +
stat_correlation(label.x = "right")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(aes(label = paste(after_stat(r.label),
after_stat(p.value.label),
after_stat(n.label),
sep = "*\"; \"*")))
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(small.r = TRUE)
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(aes(label = paste(after_stat(r.label),
after_stat(p.value.label),
after_stat(n.label),
sep = "*\"; \"*")),
method = "kendall")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(method = "kendall")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(method = "spearman")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(aes(label = paste(after_stat(r.label),
after_stat(p.value.label),
after_stat(n.label),
sep = "*\"; \"*")),
method = "spearman")
# Inspecting the returned data using geom_debug()
if (requireNamespace("gginnards", quietly = TRUE)) {
library(gginnards)
# This provides a quick way of finding out the names of the variables that
# are available for mapping to aesthetics.
# the whole of data
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", method = "pearson")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", method = "kendall")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", method = "spearman")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", output.type = "numeric")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", output.type = "markdown")
ggplot(my.data, aes(x, y)) +
geom_point() +
stat_correlation(geom = "debug", output.type = "LaTeX")
}
Run the code above in your browser using DataLab