Feature requirement for showing the positive or negative correlation in the plot
Closed this issue · 7 comments
B-1991-ing commented
Hi Houyun,
Could you add one feature requirement to show the negative correlation using the dotted curves and the positive correlation using the solid curves? Then it will be easier for people to directly see the negative or positive correlation between two matrixes.
For now, all my correlated curves are solid.
Best,
Bing
Hy4m commented
you can
set linetype = 'dashed'
parameter in geom_couple()
layer function.
B-1991-ing commented
B-1991-ing commented
I also want to know the positive or negative relationship between the matrixes.
B-1991-ing commented
Hy4m commented
This part is the same as pure ggplot2
, you need to map the linetype
to mantel's r and then adjust it using scale_linetype_manual()
.
Here's an example:
library(linkET)
library(ggplot2)
library(dplyr)
data("varechem", package = "vegan")
data("varespec", package = "vegan")
mantel <- mantel_test(varespec, varechem,
spec_select = list(Spec01 = 1:7,
Spec02 = 8:18,
Spec03 = 19:37,
Spec04 = 38:44)) %>%
mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),
pd = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf),
labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))
qcorrplot(correlate(varechem), type = "lower", diag = FALSE) +
geom_square() +
geom_couple(aes(colour = pd, size = rd, linetype = r > 0),
data = mantel,
curvature = nice_curvature()) +
scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu")) +
scale_size_manual(values = c(0.5, 1, 2)) +
scale_colour_manual(values = color_pal(3)) +
scale_linetype_manual(values = c("TRUE" = "solid", "FALSE" = "dashed")) +
guides(size = guide_legend(title = "Mantel's r",
override.aes = list(colour = "grey35"),
order = 2),
colour = guide_legend(title = "Mantel's p",
override.aes = list(size = 3),
order = 1),
fill = guide_colorbar(title = "Pearson's r", order = 3))
B-1991-ing commented
Hy4m commented
Whether the result is reasonable or not requires professional knowledge to judge.😂