Hy4m/linkET

Feature requirement for showing the positive or negative correlation in the plot

Closed this issue · 7 comments

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.
image

Best,

Bing

Hy4m commented

you can

set linetype = 'dashed' parameter in geom_couple() layer function.

Is there a way to set the negative Mantel's r with dashed lines and positive Mantel's r with solid lines?
If directly set the livetype = "dashed", all lines will be dashed.

image

I also want to know the positive or negative relationship between the matrixes.

Screenshot 2023-04-01 at 09 37 34

Hi Houyun,

Is it difficult to add the feature of the solid and dashed lines to make a difference between the positive or negative mantel test relationships, as shown above?

Best,

Bing

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))

Screenshot 2023-04-02 at 11 48 39

image

Yeah, thank you Houyun. I also added the code on making my own plots. But, in both figures, why all significant Mantel's r are positive related lines and only some non-significant Mantel's r represent negative relationship? Is it a bit strange?

Best,

Bing

Hy4m commented

Whether the result is reasonable or not requires professional knowledge to judge.😂